Trouble using WIN32OLE for excel

Discussion in 'Ruby' started by Haley Thrapp, Oct 15, 2007.

  1. Haley Thrapp

    Haley Thrapp Guest

    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/.
     
    Haley Thrapp, Oct 15, 2007
    #1
    1. Advertising

  2. Haley Thrapp

    bbiker Guest

    On Oct 15, 12:04 pm, Haley Thrapp <> 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"
     
    bbiker, Oct 15, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Masaki Suketa
    Replies:
    4
    Views:
    384
    Dave Burt
    Mar 27, 2006
  2. Li Chen
    Replies:
    2
    Views:
    159
    Li Chen
    Dec 1, 2006
  3. Li Chen
    Replies:
    3
    Views:
    127
  4. Barry Walker

    Win32OLE trouble (custom ocx)

    Barry Walker, Mar 1, 2007, in forum: Ruby
    Replies:
    10
    Views:
    239
    Masaki Suketa
    Mar 16, 2007
  5. zxem
    Replies:
    1
    Views:
    237
Loading...

Share This Page