新手问题 rails 导出 excel 插件问题

76521 · July 05, 2013 · Last by 76521 replied at July 05, 2013 · 5122 hits

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 表中的最后一条数据啊?,我哪个地方的循环写错了?求指点

timer 忘记加了吧

sheet1[timer,5] = contact.department 下面增加一行 timer += 1

#1 楼 @cxh116 果真是啊,谢谢啊

You need to Sign in before reply, if you don't have an account, please Sign up first.