roo: undefined method `upto' for nil:NilClass (NoMethodError)
HI
We are facing one issue, we don’t know what’s problem.
/home/vtrkanna/.rvm/gems/ruby-2.1.2@rails4-dev/gems/roo-1.13.2/lib/roo/base.rb:266:in `row': undefined method `upto' for nil:NilClass (NoMethodError)
Our Code file = “/home/vtrkanna/Workspace/Rails4-devt/public/Article.xls”
spreadsheetx = Roo::Spreadsheet.open(file, extension: :xls)
-#spreadsheet = Roo::Spreadsheet.open(file)
header = spreadsheetx.row(1)
(2..spreadsheetx.last_row).each do |i|
row = Hash[[header, spreadsheetx.row(i)].transpose]
puts row["Name "]
end
ISSUE
/home/vtrkanna/.rvm/gems/ruby-2.1.2@rails4-dev/gems/roo-1.13.2/lib/roo/base.rb:266:in row': undefined methodupto’ for nil:NilClass (NoMethodError)
Help us
About this issue
- Original URL
- State: open
- Created 9 years ago
- Comments: 16 (8 by maintainers)
Spent some more time looking into this. It’s a pretty tricky issue.
Roo’s sheets depend on methods like
first_rowandlast_row. These methods usually return integers, but if the sheet is empty, will returnnil. Unfortunately, thisnilvalue goes up the stack until it reaches of the methods that useuptoto iterate through rows and columns.Ideally, Roo should return an empty sheet, and an empty row or column. I’ll work on adding such behaviors in the next major version of Roo. The reason this will need a major version is it will break the behavior for users expecting those row/column methods to return an integer or nil value.
@lehug - This is a simplified version of a workaround that I ended up with:
The call to
first_rowis the important part, I’m sure there are other ways to call it without having to use the default sheet.