Win32ole --Dynamic lookup vs Static?

I am using 'win32ole' to script excel.
In python I use the COM makepy utility which allows faster processing
of ole commands. It doesn't need to do dynamic look ups.
Python code:
from win32com.client import Dispatch
xlApp = Dispatch("Excel.Application")

Does Ruby have a similar function?

I found 'olegen.rb' but after I generated a file, I haven't got it to
work.
-thanks

You can simply use the WIN32OLE object ...
It's dynamic.
PickAxe2 has a great chapter on it. ruby-doc has decent information too.
j.

···

On 11/8/05, greg.rb <ghalsey@yahoo.com> wrote:

I am using 'win32ole' to script excel.
In python I use the COM makepy utility which allows faster processing
of ole commands. It doesn't need to do dynamic look ups.
Python code:
from win32com.client import Dispatch
xlApp = Dispatch("Excel.Application")

Does Ruby have a similar function?

I found 'olegen.rb' but after I generated a file, I haven't got it to
work.
-thanks

--
"http://ruby-lang.org -- do you ruby?"

Jeff Wood

Jeff Wood wrote:

You can simply use the WIN32OLE object ...
It's dynamic.
PickAxe2 has a great chapter on it. ruby-doc has decent information too.
j.

Your answer was read the document and don't attempt to optimize???
  Read I will.

PickAxe2 on page 272-3 shows the use of olegen.rb having a 40% faster.

Does anyone know what I am asking about?

greg.rb wrote:

PickAxe2 on page 272-3 shows the use of olegen.rb having a 40% faster.

Does anyone know what I am asking about?

I know what you're talking about:

% olegen.rb "Microsoft Excel 11.0 Object Library" > excel.rb
% irb

require 'excel'
xl = Excel_Application_11.new
xl.visible = true
xl.quit

What problem were you having?

Cheers,
Dave

many thanks...however, something is still wrong. I am using the 1
click installer version. I had to download the olegen.rb from the RAA.
here is what happened:

C:\ruby\lib\ruby\site_ruby\1.8>olegen "Microsoft Excel 10.0 Object
Library" >excel.rb

C:\ruby\lib\ruby\site_ruby\1.8>irb
irb(main):001:0> require 'excel'
LoadError: No such file to load -- oleproperty
        from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
        from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
        from c:/ruby/lib/ruby/site_ruby/1.8/excel.rb:2
        from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
        from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
        from (irb):1
irb(main):002:0> require 'win32ole'
=> false
irb(main):003:0> require 'win32ole'
=> false
irb(main):004:0> require 'excel'
=> false
irb(main):005:0> xl=Excel_Application_10.new
NameError: uninitialized constant Excel_Application_10
        from (irb):5
irb(main):006:0>

···

from :0

Hi,

Grab http://raa.ruby-lang.org/gonzui/source/win32ole/lib/oleproperty.rb

Hope that helps,
Jeff

···

On Thu, Nov 10, 2005 at 04:32:13AM +0900, greg.rb wrote:

many thanks...however, something is still wrong. I am using the 1
click installer version. I had to download the olegen.rb from the RAA.
here is what happened:

C:\ruby\lib\ruby\site_ruby\1.8>olegen "Microsoft Excel 10.0 Object
Library" >excel.rb

C:\ruby\lib\ruby\site_ruby\1.8>irb
irb(main):001:0> require 'excel'
LoadError: No such file to load -- oleproperty
        from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
        from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
        from c:/ruby/lib/ruby/site_ruby/1.8/excel.rb:2
        from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
        from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
        from (irb):1
irb(main):002:0> require 'win32ole'
=> false
irb(main):003:0> require 'win32ole'
=> false
irb(main):004:0> require 'excel'
=> false
irb(main):005:0> xl=Excel_Application_10.new
NameError: uninitialized constant Excel_Application_10
        from (irb):5
        from :0
irb(main):006:0>

It worked!!!!!

irb(main):001:0> require 'excel'
=> true
irb(main):002:0> xl=Excel_Application_10.new
=> #<Excel_Application_10:0x32bde68 @progid="Excel.Application.10",
@clsid="{000
24500-0000-0000-C000-000000000046}", @dispatch=#<WIN32OLE:0x32bdc40>>
irb(main):003:0> xl.visible=1
=> 1
irb(main):004:0>

When I get a chance I will run some tests to see if it helps
performance.
Thanks.

It slowed things down. I guess "require 'excel.rb'" slows things down
if you aren't doing much work with excel to make a difference.
I had much more interesting results vs. python which I am posting on a
new thread. Ruby was 2x as fast as Python for accesing an Excel file
reading 1000 lines of data!