Spreadsheet gem:无法创建空工作簿

时间:2013-03-20 00:54:10

标签: ruby spreadsheet

我正在使用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)这是宝石中的一个错误还是预期崩溃?

1 个答案:

答案 0 :(得分:3)

我通过电子邮件发送了该项目的维护者,他们表示这是预期的。