如何将数据导出到我知道的Excel文件中

时间:2018-07-04 08:51:05

标签: ruby-on-rails-4

大家好,我在Redmine上工作,我想将所有表中的所有数据导出到excel文件中。如果有人有主意。谢谢

routes.rb

get '/export', to: 'export#index'

export_controller.rb

class ExportController < ApplicationController

def index
    @attachments=Attachment.all
    @projects=Project.all

    respond_to do |format|
    format.html
    format.xlsx
    end
end     
end

index.html.erb

<h1>List of products</h1>
<%= link_to 'Download as .xlsx', export_path(format: :xlsx) %>

index.xlsx.axlsx

wb = xlsx_package.workbook
wb.add_worksheet(name: "Attachments") do |sheet|
@attachments.each do |product|
  sheet.add_row [attachment.id, attachment.filename]
 end
end

error

0 个答案:

没有答案