I'm using https://github.com/zdavatz/spreadsheet version 0.8.3
I've got code that iterates over a collection and creates a worksheet in the same workbook for each item. When the collection is empty, the code that executes ends up looking like:
io = StringIO.new
book = Spreadsheet::Workbook.new
book.write(io)
The last line raises:
TypeError: can't convert nil into Integer
spreadsheet/excel/writer/workbook.rb:636:in `pack'
spreadsheet/excel/writer/workbook.rb:636:in `write_window1'
spreadsheet/excel/writer/workbook.rb:419:in `write_from_scratch'
spreadsheet/excel/writer/workbook.rb:644:in `write_workbook'
spreadsheet/writer.rb:12:in `write'
spreadsheet/workbook.rb:124:in `write'
Changing my code to this fixes things:
io = StringIO.new
book = Spreadsheet::Workbook.new
book.create_worksheet if book.worksheets.empty?
book.write(io)
But I'd rather not have to include the call to create_worksheet
. My questions are:
a) am I doing anything wrong in my code?
b) is this a bug in the gem or is the crash expected?
I emailed the maintainer of the project and they indicated that this is expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With