Reading data from excel

Hi,
I'm brand new to Ruby.
Can somebody share their expertise on how to open and read data from
excel using ruby?
Thanks in advance.

And also any suggestions on where/how to learn Ruby would be very
helpful and appreciated.

···

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

Hi,
I'm brand new to Ruby.
Can somebody share their expertise on how to open and read data from
excel using ruby?
Thanks in advance.

A very rudimentary version that shows the logic:

require 'win23ole'

        application = WIN32OLE.new('Excel.Application')
        worksheet
=application.Workbooks.Open(excelFileName).Worksheets(workSheetName)
        worksheet.Activate

        contLoop = true # Dummy counter for the loop

        while contLoop do
          colVal = worksheet.Cells(row, column).Value

          if (colVal) then
            # This field is not NIL, this means that this row contains a entry
            # Get the SecurityObject corresponding to the cusip, and
get the coupon
            do processing ....
          else
            # This signifies the end - no cash column value, no short
name value.
            # End the loop
            contLoop = false
          end
          # go to the next Row
          row += 1
        end

        # we are done
        application.Workbooks.Close

And also any suggestions on where/how to learn Ruby would be very
helpful and appreciated.

Pickaxe is a great book. You can find an online version at
http://www.ruby-doc.org/docs/ProgrammingRuby/html/index.html

All the best,
-Madan.

···

On 6/5/06, Parvinder Ghotra <ghotrapa@yahoo.com> wrote:

Parvinder Ghotra wrote:

Hi,
I'm brand new to Ruby.
Can somebody share their expertise on how to open and read data from excel using ruby?
Thanks in advance.

And also any suggestions on where/how to learn Ruby would be very helpful and appreciated.

In addition to using win32ole, also see the "parseexcel" package.

http://raa.ruby-lang.org/project/parseexcel/

Regards,

Dan

Can somebody share their expertise on how to open and read data from
excel using ruby?

I would also recommend parseexcel. The maintainer is very friendly and the
package works quite well.

require "parseexcel/parseexcel"
file_name = "/your/file/name/here.xls"
workbook = Spreadsheet::ParseExcel.parse(file_name)
worksheet = workbook.worksheet(0) # the first sheet in the book
worksheet.each { |row| puts row.at(0) } # print the first column of each row

And also any suggestions on where/how to learn Ruby would be very

helpful and appreciated.

I would recommend "Why's (Poignant) Guide to Ruby" if your tolerance for the
absurd is high. (http://poignantguide.net/ruby/\) Otherwise, I would
recommend "Learn to Program" as a place to start online. (
http://pine.fm/LearnToProgram/\)

Good luck.

Sean Carley
http://sean-carley.blogspot.com/

···

On 6/5/06, Parvinder Ghotra <ghotrapa@yahoo.com> wrote:

Try this link, it helped me greatly when I was trying to wrap my head around
how to script excel

http://wiki.rubygarden.org/Ruby/page/show/ScriptingExcel

···

On 6/5/06, Parvinder Ghotra <ghotrapa@yahoo.com> wrote:

Hi,
I'm brand new to Ruby.
Can somebody share their expertise on how to open and read data from
excel using ruby?
Thanks in advance.

And also any suggestions on where/how to learn Ruby would be very
helpful and appreciated.

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

I cannot read excel in require 'fox16'. How can I do to run excel file?

···

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

Simplier approach, if possible, save the excel in csv format.
Then parse the csv using fastercsv (http://fastercsv.rubyforge.org/)

···

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

Oops, 'win23ole' should have read 'win32ole'

-Madan.

···

On 6/5/06, Madan Manoharan <madan.manoharan@gmail.com> wrote:

On 6/5/06, Parvinder Ghotra <ghotrapa@yahoo.com> wrote:
> Hi,
> I'm brand new to Ruby.
> Can somebody share their expertise on how to open and read data from
> excel using ruby?
> Thanks in advance.

A very rudimentary version that shows the logic:

require 'win23ole'

Madan Thanks for your quick response.

I'm trying to just open the excel application using the code below:

require 'win32ole'

excel = WIN32OLE.new('Excel.Application')
excel['Visible'] = true;

Something happens but i excel doesn't open up.
do i need to add something to the above code?
Thanks

···

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

Madan Manoharan wrote:

Hi,
I'm brand new to Ruby.
Can somebody share their expertise on how to open and read data from
excel using ruby?
Thanks in advance.

A very rudimentary version that shows the logic:

require 'win23ole'

        application = WIN32OLE.new('Excel.Application')
        worksheet
=application.Workbooks.Open(excelFileName).Worksheets(workSheetName)
        worksheet.Activate

        contLoop = true # Dummy counter for the loop

        while contLoop do
          colVal = worksheet.Cells(row, column).Value

          if (colVal) then
            # This field is not NIL, this means that this row contains a
entry
            # Get the SecurityObject corresponding to the cusip, and
get the coupon
            do processing ....
          else
            # This signifies the end - no cash column value, no short
name value.
            # End the loop
            contLoop = false
          end
          # go to the next Row
          row += 1
        end

        # we are done
        application.Workbooks.Close

And also any suggestions on where/how to learn Ruby would be very
helpful and appreciated.

Pickaxe is a great book. You can find an online version at
Programming Ruby: The Pragmatic Programmer's Guide

All the best,
-Madan.

Thanks everybody for your time and help.

Issue:
I'm getting an error "undefined local variable row" at line

          colVal = worksheet.Cells(row, column).Value

Thanks for your help,
-Parvinder

···

On 6/5/06, Parvinder Ghotra <ghotrapa@yahoo.com> wrote:

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

Thanks Gary, it seems like a pretty good source of information.
Parvinder

···

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

win32ole

···

On May 22, 6:06 pm, Cool Wong <coolwon...@yahoo.com> wrote:

I cannot read excel in require 'fox16'. How can I do to run excel file?
--
Posted viahttp://www.ruby-forum.com/.

Parvinder Ghotra wrote:

Madan Thanks for your quick response.

I'm trying to just open the excel application using the code below:

require 'win32ole'

excel = WIN32OLE.new('Excel.Application')
excel['Visible'] = true;

Something happens but i excel doesn't open up.
do i need to add something to the above code?
Thanks

Parvinder-

Add a line of code to create a new workbook or open an existing one:

wb = excel.Workbooks.Add

  OR

wb = excel.Workbooks.Open(filename)

Mully

···

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