我想"跑"迭代我的数据库,并将数据插入行。 但是,我一次又一次地得到同样的错误
" TypeError:没有将Spreadsheet :: Row隐式转换为整数"
我的代码看起来像这样:
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet
sheet1.row(0).push "Time", "Name", "Phone", "Email"
[0,1,2,3].each{|col| sheet1.column(col).width = 19}
sheet1.each do |row|
object.each do |o|
sheet1.(row).push o.time, o.name, o.phone, o.email
end
end
book.write '../excel.xls'
先谢谢你们!
答案 0 :(得分:2)
您已将row
sheet1.(row).
传递给期望整数的方法。
object.each_with_index do |o, i|
sheet1.insert_row i+1, [ o.time, o.name, o.phone, o.email ]
end