当用户使用Ransack执行搜索时,我正在使用AXLSX从网站上显示的表格生成xlsx文件。我的问题是结果在网站上分页,但我希望电子表格显示完整的结果集,而不是目前的15条记录。
控制器
def index
@search = Campaign.search(params[:q])
@campaigns = @search.result.page(params[:page]||1)
respond_to do |format|
format.html
format.xlsx{ render xlsx: 'Campaigns' }
end
end
链接
= link_to '<i class="glyphicon glyphicon-cloud-download"></i>'.html_safe, admin_campaigns_path(format: :xlsx), title: "Download Campaign XLS", rel: 'tooltip'
Campaigns.xlsx.axlsx
require 'axlsx'
xlsx_package = Axlsx::Package.new
wb = xlsx_package.workbook
wb.add_worksheet(name: "Campaigns") do |sheet|
style1 = sheet.styles.add_style(:bg_color => "EF0920", :fg_color => "FFFFFF", :b => "true")
sheet.add_row ["Header", "Header", "Header", "Header","Header","Header","Header","Header","Header","Header","Header","Header"], :style => style1
@campaigns.each do |campaign|
sheet.add_row [campaign.data,campaign.data,campaign.data,campaign.data,campaign.data,ccampaign.data,campaign.data,campaign.data,campaign.data,campaign.data,campaign.data]
end
end
我在考虑将广告系列的调用更改为其他内容并删除分页但不确定如何执行此操作。
答案 0 :(得分:0)
想出来:
def index
@search = Campaign.search(params[:q])
@campaigns = @search.result
respond_to do |format|
format.html{@campaigns = @search.result.page(params[:page]||1)}
format.xlsx{ render xlsx: 'Campaigns' }
end
end