1

我想在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

并且文件是空的。我如何传递对象?

4

1 回答 1

0

对于未来的我:

 @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
    }
于 2012-10-08T13:14:34.000 回答