0

I'am trying to export data to Excel spread sheet in rails using "write_xlsx_rails" gem.

Controller:

def download
   render xlsx: "download", disposition: "attachment", filename:   "my_new_filename.xlsx"
end  

View(download.xlsx.wxlsx):

    # Add a worksheet
    worksheet = workbook.add_worksheet

    # Add and define a format
    format = workbook.add_format # Add a format
    format.set_bold
    format.set_color('red')
    format.set_align('center')

     # Write a formatted and unformatted string, row and column notation.
     col = row = 0
     worksheet.write(row, col, "Hi Excel!", format)
     worksheet.write(1,   col, "Hi Excel!")

     # Write a number and a formula using A1 notation
     worksheet.write('A3', 1.2345)
     worksheet.write('A4', '=SIN(PI()/4)')

but I'm getting error like this:

uninitialized constant ActionView::CompiledTemplates::WriteXLSX

pnuts
  • 58,317
  • 11
  • 87
  • 139
Sathibabu P
  • 649
  • 1
  • 7
  • 15
  • Did you re-start the server after installing the gem? Take a look at http://stackoverflow.com/questions/10588749/uninitialized-constant-actionviewcompiledtemplatescategory and http://stackoverflow.com/questions/21037955/uninitialized-constant-actionviewcompiledtemplatesbootstrappagination These may help you solve your problem. – K M Rakibul Islam Nov 09 '15 at 06:19
  • According to write_xlsx_rails documentation use `format.xlsx{render xlsx: "download", disposition: "attachment", filename: "my_new_filename.xlsx"}` – Pardeep Saini Nov 09 '15 at 06:37

1 Answers1

0

According to write_xlsx_rails documentation, if you specify the file name you must use format for e.g.

def download
  respond_to do |format|      
   format.xlsx{render xlsx: "download", disposition: "attachment", filename: "my_new_filename.xlsx"}
  end
end  
Pardeep Saini
  • 2,084
  • 1
  • 18
  • 29