0

My workbook always named like my template "invoices_generate.xlsx". How can i rename this File ?

Template "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
Drextor
  • 433
  • 1
  • 6
  • 24

2 Answers2

0

Do you have the axlsx_rails gem added as well? 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

beaorn
  • 454
  • 3
  • 9
  • 1
    Using name under `add_worksheet` only names the sheet. So yes, it will have to be done in the controller with a `render :xlsx` statement. Without this, there will be no filename http header, and the browser will guess a name based on the URL. – noel Jun 01 '16 at 18:52
  • Actually this doesn't resolve the original question because this answer changes the name of the worksheet, not the file – eduardo a Sep 24 '21 at 23:08
0

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  
eduardo a
  • 152
  • 4
  • 17