5

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?

1
  • 3
    This looks like expected behavior.
    – Linuxios
    Mar 20, 2013 at 0:55

1 Answer 1

3

I emailed the maintainer of the project and they indicated that this is expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.