我想在AJAX搜索后导出数据,所以我创建了这样的动作(在我下载工作后会添加搜索条件):
def export
require 'spreadsheet'
@data = Item.all
report = Spreadsheet::Workbook.new
sheet = report.create_worksheet :name => "data"
spreadsheet = StringIO.new
report.write spreadsheet
send_data spreadsheet.string, :filename => "report.xls", :type => "application/vnd.ms-excel"
end
文件为空。我如何传递物品?
答案 0 :(得分:0)
对于未来的ME:
@data = Item.all
report = Spreadsheet::Workbook.new
sheet = report.create_worksheet :name => "data"
sheet.row(0).concat %w{Id CreatedAt}
@data.each_with_index { |item, i|
sheet.row(i+1).push item.id,item.created_at
}