win32ole and excel and copy

Discussion in 'Ruby' started by Li Chen, Nov 8, 2006.

  1. Li Chen

    Li Chen Guest

    Hi all,

    I use wind32ole to import data and create graphs into Excel. I find the
    graphs can't be copied or resized. Any comments?

    Thanks,

    Li

    --
    Posted via http://www.ruby-forum.com/.
     
    Li Chen, Nov 8, 2006
    #1
    1. Advertising

  2. Li Chen

    Greg Halsey Guest

    Li Chen wrote:
    > Hi all,
    >
    > I use wind32ole to import data and create graphs into Excel. I find the
    > graphs can't be copied or resized. Any comments?
    >
    > Thanks,
    >
    > Li

    # Here is sample code to copy a chart in a worksheet:

    require 'win32ole'

    xl=WIN32OLE::new('Excel.Application')
    xl.Visible=1 #show excel

    xl.Workbooks.Open('c:\\testme.xls') #will open a file

    xl.sheets(1).activate #activate the sheet you want

    xl.ActiveSheet.ChartObjects("Chart 1").Activate #activate the chart

    xl.ActiveChart.ChartArea.Select
    xl.ActiveChart.ChartArea.Copy
    xl.Windows("testme.xls").Activate
    xl.Cells(50,1).Select # select row and col to paste chart
    xl.ActiveSheet.Paste


    #xl.ActiveWorkbook.Close()
    #xl.Quit

    #greg

    --
    Posted via http://www.ruby-forum.com/.
     
    Greg Halsey, Nov 8, 2006
    #2
    1. Advertising

  3. Li Chen

    Li Chen Guest

    Greg Halsey wrote:
    >> # Here is sample code to copy a chart in a worksheet:

    >
    > require 'win32ole'
    >
    > xl=WIN32OLE::new('Excel.Application')
    > xl.Visible=1 #show excel
    >
    > xl.Workbooks.Open('c:\\testme.xls') #will open a file
    >
    > xl.sheets(1).activate #activate the sheet you want
    >
    > xl.ActiveSheet.ChartObjects("Chart 1").Activate #activate the chart
    >
    > xl.ActiveChart.ChartArea.Select
    > xl.ActiveChart.ChartArea.Copy
    > xl.Windows("testme.xls").Activate
    > xl.Cells(50,1).Select # select row and col to paste chart
    > xl.ActiveSheet.Paste
    >
    >
    > #xl.ActiveWorkbook.Close()
    > #xl.Quit
    >
    > #greg


    Hi Greg,

    I try the script but I find it only open an designated file only. I
    still can't copy the chart. BTW there is plug-in in Excel called Visual
    Basic editor. Is it the same as Visual Basic environment?

    Thanks,

    Li

    --
    Posted via http://www.ruby-forum.com/.
     
    Li Chen, Nov 8, 2006
    #3
    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. Alex
    Replies:
    2
    Views:
    1,236
  2. Replies:
    26
    Views:
    2,120
    Roland Pibinger
    Sep 1, 2006
  3. Masaki Suketa
    Replies:
    4
    Views:
    384
    Dave Burt
    Mar 27, 2006
  4. Li Chen
    Replies:
    3
    Views:
    106
    Li Chen
    Nov 12, 2006
  5. zxem
    Replies:
    1
    Views:
    237
Loading...

Share This Page