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

76521 · 2013年07月05日 · 最后由 76521 回复于 2013年07月05日 · 5134 次阅读

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 果真是啊,谢谢啊

需要 登录 后方可回复, 如果你还没有账号请 注册新账号