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

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

Alle venerdì 23 febbraio 2007, Ruhul A. 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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs