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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
87303c28b23af9aa69831b6bd156fdb0?d=identicon&s=25 Ruhul Amin (tuhin_cse99)
on 2007-02-23 09:36
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
C40020a47c6b625af6422b5b1302abaf?d=identicon&s=25 Stefano Crocco (crocco)
on 2007-02-23 16:34
(Received via mailing list)
Alle venerdì 23 febbraio 2007, Ruhul Amin ha scritto:
> 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
This topic is locked and can not be replied to.