Hi all,
I recently play with win32ole library. In order to use it I put a line
at the top of the script
require 'win32ole'
so that Ruby knows where to find the library. It is my understanding I
should be able to access all the classes/modules within the file. But
this is not the case. In order to get access to ExcelConst I need to add
two more lines
module ExcelConst
end
near the top of the script.
I am a little bit confused. Why is that? Is this only special to
win32ole library or common to many Ruby libraries?
Any comments will be appriciated.
Li
And the follows are the fragment of the script:
···
###
require 'win32ole'
module ExcelConst
end
excel = WIN32OLE.new("Excel.Application")
workbook = excel.Workbooks.Add
excelchart = workbook.Charts.Add
....
WIN32OLE.const_load(excel, ExcelConst)
excelchart.ChartType = ExcelConst::XlConeCol
###screen output
C:\>irb
irb(main):001:0> require 'win32ole'
=> true
irb(main):002:0>
irb(main):003:0* module ExcelConst
irb(main):004:1> end
=> nil
irb(main):005:0>
irb(main):006:0* excel = WIN32OLE.new("Excel.Application")
=> #<WIN32OLE:0x2c268f0>
irb(main):007:0> workbook = excel.Workbooks.Add
=> #<WIN32OLE:0x2c24154>
irb(main):008:0> excelchart = workbook.Charts.Add
=> #<WIN32OLE:0x2c21954>
irb(main):009:0>
irb(main):010:0* WIN32OLE.const_load(excel, ExcelConst)
=> nil
irb(main):011:0> puts excelchart.ChartType = ExcelConst::XlConeCol
105
=> nil
--
Posted via http://www.ruby-forum.com/.