How to operate an existing Excel file?

<<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!

alexeyomux wrote:

<<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

···

--
Posted via http://www.ruby-forum.com/\.

alexeyomux wrote:

<<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')

David

···

--
Posted via http://www.ruby-forum.com/\.

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.

···

On Aug 8, 2:08 pm, "alexeyomux" <alexeyo...@yahoo.com.cn> wrote:

<<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!