Drextor
Drextor

Reputation: 433

Rails Gem "Axlsx" - Rename Workbook

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

Upvotes: 0

Views: 1136

Answers (2)

eduardo a
eduardo a

Reputation: 150

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  

Upvotes: 0

beaorn
beaorn

Reputation: 454

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

Upvotes: 0

Related Questions