我正在使用https://github.com/zdavatz/spreadsheet版本 0.8.3
我有代码迭代一个集合并在同一个工作簿中为每个项目创建一个工作表。当集合为空时,执行的代码最终看起来像:
io = StringIO.new
book = Spreadsheet::Workbook.new
book.write(io)
最后一行提出:
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'
将我的代码更改为此可以解决问题:
io = StringIO.new
book = Spreadsheet::Workbook.new
book.create_worksheet if book.worksheets.empty?
book.write(io)
但我宁愿不必包括对create_worksheet
. 我的问题是:
a)我在我的代码中做错了什么吗?
b)这是 gem 中的错误还是预期的崩溃?