[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to operate an existing Excel file?

alexeyomux

8/8/2007 6:08:00 PM

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


3 Answers

Todd Burch

8/8/2007 6:45:00 PM

0

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

David Mullet

8/9/2007 12:23:00 AM

0

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

http://rubyonwindows.blogspot.com/2007/03/automating-excel-with-ruby-applic...
http://rubyonwindows.blogspot.com/2007/03/automating-excel-with-ruby-wor...
http://rubyonwindows.blogspot.com/search/l...

David
--
Posted via http://www.ruby-....

greg.kujawa

8/9/2007 12:37:00 AM

0

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!

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.