Rails gem axlsx宝石多张

时间:2017-02-16 14:24:28

标签: ruby-on-rails xlsx axlsx

是否可以使用gem axlsx在xlsx中导出多张表格。如果没有,请以其他方式向我推荐。

我想在不同的工作表中导出@ search,@ searchg,@clients,@ odrtimes的值。

@search = Operation.where(:date => params[:from_date].to_datetime..(params[:to_date].to_datetime + 1.day))
@searchg = Guard.where(:status => true).where(:induction_date => params[:from_date].to_datetime..(params[:to_date].to_datetime + 1.day))
@searcht = Guard.where(:status => false).where(:terminate_date => params[:from_date].to_datetime..(params[:to_date].to_datetime + 1.day))
@clients = Client.where(:status => false).where(:terminate_date => params[:from_date].to_datetime..(params[:to_date].to_datetime + 1.day))
@overtimes = Overtime.where(:date => params[:from_date].to_datetime..(params[:to_date].to_datetime + 1.day))
   respond_to do |format|
        format.js
        format.xlsx {render xlsx: 'report', filename: "Operation_reports_#{params[:from_date]}_#{params[:to_date]}.xlsx"}
   end

1 个答案:

答案 0 :(得分:3)

是的,axlsx支持多张纸。实际上,您可以在 its readme中的第一个代码段中看到它:

Axlsx::Package.new do |p|
  p.workbook.add_worksheet(:name => "Pie Chart") do |sheet|
    sheet.add_row ["Simple Pie Chart"]
    %w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
    sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "example 3: Pie Chart") do |chart|
      chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"],  :colors => ['FF0000', '00FF00', '0000FF']
    end
  end
  p.serialize('simple.xlsx')
end