简体   繁体   English

Rails Gem "Axlsx" - 重命名工作簿

[英]Rails Gem "Axlsx" - Rename Workbook

My workbook always named like my template "invoices_generate.xlsx".我的工作簿总是像我的模板一样命名为“invoices_generate.xlsx”。 How can i rename this File ?我怎样才能重命名这个文件?

Template "invoices_generate.xlsx.axlsx" :模板“invoices_generate.xlsx.axlsx”:

wb = xlsx_package.workbook

    wb.add_worksheet(:name => "Beleg") do |sheet|  

    .
    .
    .

    sheet.column_widths 2 , 11, 11, 11, 11, 23, 3

    end

Do you have the axlsx_rails gem added as well? 您是否还添加了axlsx_rails gem? If so: 如果是这样的话:

wb = xlsx_package.workbook
wb.add_worksheet(name: "Beleg") do |sheet|
  sheet.column_widths 2 , 11, 11, 11, 11, 23, 3
end

See https://github.com/straydogstudio/axlsx_rails#template for more details and if that doesn't work try setting the filename from the controller action rendering the xlsx template as described here: https://github.com/straydogstudio/axlsx_rails#file-name 有关更多详细信息,请参见https://github.com/straydogstudio/axlsx_rails#template ,如果这样不起作用,请尝试按如下所述通过呈现xlsx模板的控制器操作设置文件名: https : //github.com/straydogstudio/ axlsx_rails#文件名

For future references: In the controller, on the function where generate the workbook供以后参考:在控制器中,在生成工作簿的功能上

def index
  @users =  User.all

  render xlsx: 'export', filename: 'my_new_filename.xlsx' //Render with export and naming the file
  respond_to do |format|
    format.html
    format.xlsx
  end
end  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM