How to operate an existing Excel file?

A

alexeyomux

<<Programming Ruby 2nd>> teaches me how to create a new Excel file and add
something to it, but now I have a task that there were some existing Excel
files with data, what should I do is opening the files one by one and read
the data for doing something.
I try to use the WIN32OLE .connect() function, but it didn't work.
Is there other better way to do so?
thanks a lot!
 
T

Todd Burch

alexeyomux said:
<<Programming Ruby 2nd>> teaches me how to create a new Excel file and
add
something to it, but now I have a task that there were some existing
Excel
files with data, what should I do is opening the files one by one and
read
the data for doing something.
I try to use the WIN32OLE .connect() function, but it didn't work.
Is there other better way to do so?
thanks a lot!

connect establishes a connection between your ruby and an already
running instance of Excel.
open opens a new instance of Excel, whether Excel is running at the
time or not.

After you establish a session with Excel, using either of the above
methods, then you need to open the workbook you want.

Todd
 
D

David Mullet

alexeyomux said:
<<Programming Ruby 2nd>> teaches me how to create a new Excel file and
add
something to it, but now I have a task that there were some existing
Excel
files with data, what should I do is opening the files one by one and
read
the data for doing something.
I try to use the WIN32OLE .connect() function, but it didn't work.
Is there other better way to do so?
thanks a lot!

excel = WIN32OLE.new('Excel.Application')
workbook = excel.Workbooks.Open('c:\temp\MyWorkbook.xls')

http://rubyonwindows.blogspot.com/2007/03/automating-excel-with-ruby-application.html
http://rubyonwindows.blogspot.com/2007/03/automating-excel-with-ruby-workbook.html
http://rubyonwindows.blogspot.com/search/label/excel

David
 
G

gregarican

<<Programming Ruby 2nd>> teaches me how to create a new Excel file and add
something to it, but now I have a task that there were some existing Excel
files with data, what should I do is opening the files one by one and read
the data for doing something.
I try to use the WIN32OLE .connect() function, but it didn't work.
Is there other better way to do so?
thanks a lot!

What the other posters suggested are great tips. Personally I have
been able to leverage a lot of great time savers using Ruby's WIN32OLE
and Excel. For example, reading lots of SQL data sets and pumping them
into new Excel worksheets, reading and modifying existing Excel
spreadsheets, etc. One recent project involved taking an SQL query
script and exporting the results to Excel. From there that Excel file
served as the data source for a Word mail merge. Automated all to the
point of a scheduled job that automatically runs each reporting
period. Good stuff for sure. And a heck of a lot less code and effort
than doing the same thing in VB, C#, etc.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top