require "spreadsheet"
def download
Spreadsheet.client_encoding = "UTF-8"
bookString = StringIO.new
book = Spreadsheet.open "#{Rails.root}/public/report_template/warehouseListReport.xls"
contacts = Contact.all
sheet1 = book.worksheet 0
timer = 1
sheet1[0,6] = ' '
for contact in contacts
sheet1[timer,0] = contact.id
sheet1[timer,1] = contact.first_name
sheet1[timer,2] = contact.last_name
sheet1[timer,3] = contact.email
sheet1[timer,4] = contact.title
sheet1[timer,5] = contact.department
end
sheet1.each do |row|
# logger.error row[1].to_s
end
book.write bookString
send_data bookString.string,:filename => '123.xls'
end
为什么导出到 123.xls 表中的数据只有 contacts 表中的最后一条数据啊?,我哪个地方的循环写错了?求指点