Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set a range of cells in Excel using win32ole #2527

Open
chuckremes opened this issue Jan 27, 2015 · 5 comments
Open

Can't set a range of cells in Excel using win32ole #2527

chuckremes opened this issue Jan 27, 2015 · 5 comments
Labels

Comments

@chuckremes
Copy link

@chuckremes chuckremes commented Jan 27, 2015

Works in MRI but fails in JRuby. Maybe related to #1932 but I'm not certain.

require 'win32ole'

begin
  # Create an instance of the Excel application object
  excel = WIN32OLE.new('Excel.Application')

  # Make Excel visible
  excel.Visible = 1
  excel.DisplayAlerts = false

  # Add a new Workbook object
  wb = excel.Workbooks.Add

  # Get the first Worksheet
  ws = wb.Worksheets(1)

  # Can set a single value, works on JRuby and MRI
  ws.Range("A1").Value = 17

  # Should be able to set a range of values, works on MRI but fails on JRuby
  ws.Range("B1:C2").Value = [
    ["b1", "c1"],
    ["b2", "c2"]
  ]

rescue => e
  p e
ensure
  #excel.Quit
end

return:

java.lang.RuntimeException: createVariant() not implemented for class org.jruby.RubyArray

This example is a very common way to set values in Excel using Ruby. The workaround is to set each cell individually but that means a performance hit of 10x or greater (probably due to crossing into/out-of COM all the time).

@basex
Copy link

@basex basex commented Apr 28, 2015

any solution for this?

@chuckremes
Copy link
Author

@chuckremes chuckremes commented May 2, 2016

Ping. Just ran into this again on Windows. Anything I can do to help (other than learn to learn how to code to the windows api)?

@chuckremes
Copy link
Author

@chuckremes chuckremes commented May 2, 2016

@enebo I should probably ping you directly... unless the project has added some more Windows guys, you're the only one I know! :)

@enebo
Copy link
Member

@enebo enebo commented May 2, 2016

@chuckremes I don't actually have Excel so I think I got paralyzed into looking into this.

@enebo
Copy link
Member

@enebo enebo commented May 2, 2016

@chuckremes I am not asking you to buy me Excel either. I just wish we could have figured out how to make a nice exerciser for this. I am not the windows guy you think I am :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants