[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

undefined method `at' for nil:NilClass while i use parseexce

Ruhul Amin

2/23/2007 8:36:00 AM

I use this code to open my '2007-02-231028.xls' file. the file is in the
same directory of the program.
my code:

require 'parseexcel'

workbook = Spreadsheet::ParseExcel.parse('2007-02-231028.xls')

worksheet = workbook.worksheet(0)

skip = 2
worksheet.each(skip) { |row|
# a row is actually just an Array of Cells..
first_cell = row.at(0)

}

Error is:
undefined method `at' for nil:NilClass

I can not understand the error. please help me as i am a niwbie in ruby

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

1 Answer

Stefano Crocco

2/23/2007 3:33:00 PM

0

Alle venerdì 23 febbraio 2007, Ruhul Amin ha scritto:
> I use this code to open my '2007-02-231028.xls' file. the file is in the
> same directory of the program.
> my code:
>
> require 'parseexcel'
>
> workbook = Spreadsheet::ParseExcel.parse('2007-02-231028.xls')
>
> worksheet = workbook.worksheet(0)
>
> skip = 2
> worksheet.each(skip) { |row|
> # a row is actually just an Array of Cells..
> first_cell = row.at(0)
>
> }
>
> Error is:
> undefined method `at' for nil:NilClass
>
> I can not understand the error. please help me as i am a niwbie in ruby

The error message simply means that you're calling the method 'at' for an
object of class NilClass (that is, nil). Since nil doesn't have a at method,
you get an error. It seems that worksheet.each passes nil to the block,
instead of an array. I'm not familiar with parseexcel, so I can't tell you
why it does that. I'd suggest you to check the class of row before using it:

worksheet.each(skip) { |row|
puts row.class
first_cell=row.at(0)
}

This may give you an idea about why the block is passed nil instead than an
array.

I hope this helps

Stefano