Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Trouble using WIN32OLE for excel

Reply
Thread Tools

Trouble using WIN32OLE for excel

 
 
Haley Thrapp
Guest
Posts: n/a
 
      10-15-2007
I am trying to do some things that seem pretty basic to me using excel.
Basically, I have a two column spreadsheet that I would like to make a
scatterplot out of. I am able to create a chart, but I run into issues
as soon as I try to give it a title. Any ideas? Also, if there are any
experts out there, I am looking for a good reference for using the
WIN32OLE in ruby. I am not very experienced with the WIN32OLE. I have
also tried setting curr_chart.HasTitle and
curr_chart.ChartTitle.Characters as I have seen in other threads, but
none of these work for me. Is it possible I am missing a package even
though I am able to handle all the other work I have tried with Excel?

require 'win32ole'
excel = WIN32OLE.new("excel.application")
excel['Visible'] = TRUE

module ExcelConsts
end

WIN32OLE.const_load(excel, ExcelConsts)

workbook = excel.Workbooks.Add
worksheet = workbook.Worksheets(1)

*snip*

charts = excel.Charts
charts.Add

curr_chart = excel.Charts(1)
curr_chart.Activate
curr_chart.ChartType=ExcelConsts::XlLineMarkers
curr_chart.ChartTitle.Text = "Testing chart title"


The error I am getting:

parse_sizeVlatency.rb:118:in `method_missing': (WIN32OLERuntimeError)
OLE error code:800A03EC in Microsoft Office Excel
Unable to set the Text property of the ChartTitle class
HRESULT error code:0x80020009
Exception occurred. from parse_sizeVlatency.rb:118



Thanks!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
bbiker
Guest
Posts: n/a
 
      10-15-2007
On Oct 15, 12:04 pm, Haley Thrapp <haley.thr...@gmail.com> wrote:
> I am trying to do some things that seem pretty basic to me using excel.
> Basically, I have a two column spreadsheet that I would like to make a
> scatterplot out of. I am able to create a chart, but I run into issues
> as soon as I try to give it a title. Any ideas? Also, if there are any
> experts out there, I am looking for a good reference for using the
> WIN32OLE in ruby. I am not very experienced with the WIN32OLE. I have
> also tried setting curr_chart.HasTitle and
> curr_chart.ChartTitle.Characters as I have seen in other threads, but
> none of these work for me. Is it possible I am missing a package even
> though I am able to handle all the other work I have tried with Excel?
>
> require 'win32ole'
> excel = WIN32OLE.new("excel.application")
> excel['Visible'] = TRUE
>
> module ExcelConsts
> end
>
> WIN32OLE.const_load(excel, ExcelConsts)
>
> workbook = excel.Workbooks.Add
> worksheet = workbook.Worksheets(1)
>
> *snip*
>
> charts = excel.Charts
> charts.Add
>
> curr_chart = excel.Charts(1)
> curr_chart.Activate
> curr_chart.ChartType=ExcelConsts::XlLineMarkers
> curr_chart.ChartTitle.Text = "Testing chart title"
>
> The error I am getting:
>
> parse_sizeVlatency.rb:118:in `method_missing': (WIN32OLERuntimeError)
> OLE error code:800A03EC in Microsoft Office Excel
> Unable to set the Text property of the ChartTitle class
> HRESULT error code:0x80020009
> Exception occurred. from parse_sizeVlatency.rb:118
>
> Thanks!
> --
> Posted viahttp://www.ruby-forum.com/.


This is what I found in the Microsoft Office Excel 2003 Visual Basic
Reference (VBAXL10.CHM), perhaps it will help.

Using the ChartTitle Object
Use the ChartTitle property to return the ChartTitle object. The
following example adds a title to embedded chart one on the worksheet
named "Sheet1."

With Worksheets("sheet1").ChartObjects(1).Chart
.HasTitle = True
.ChartTitle.Text = "February Sales"
End With

Remarks
The ChartTitle object doesn't exist and cannot be used unless the
HasTitle property for the chart is True.

This might work ... not tested
curr_chart.HasTitle = 'True'
curr_chart.ChartTitle.Text = "Testing chart title"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WIN32OLE - failed to create WIN32OLE zxem Ruby 1 12-19-2007 07:01 PM
Win32OLE trouble (custom ocx) Barry Walker Ruby 10 03-16-2007 02:00 PM
How to populate a 2D array data into Excel using WIN32OLE Li Chen Ruby 3 01-21-2007 10:51 PM
How to get value of constants in Excel using WIN32OLE Li Chen Ruby 2 12-01-2006 02:43 PM
WIN32OLE#[] and WIN32OLE#[]= method in Ruby 1.9 (or later) Masaki Suketa Ruby 4 03-27-2006 11:17 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57