1

I'm trying to send .xlsx file generated by Axlsx usind send_file.

send_file "#{RAILS_ROOT}/public/excel/test.xlsx"

In debug using Webrick server it works correctly, but on the production server (Windows server 2008 R2 with IIS and Helicon Zoo) it sends empty/corrupted xlsx file.

File in the path on production server is not empty.

How can I fix this?

Here is rails log

Started GET "/export/excel/summary_report/2" for 192.168.1.108 at 2014-02-22 22:59:57 +0000
  Processing by ExportController#export_excel_report as HTML
  Parameters: {"report_class"=>"summary_report", "entries"=>"2"}
Rendered tables/_csv_header_cell.slim (15.6ms)
Rendered tables/_csv_header_cell.slim (0.0ms)
Rendered tables/_csv_header_cell.slim (0.0ms)
Rendered tables/_csv_header_row.slim (15.6ms)
Rendered tables/_csv_header.slim (31.2ms)
Rendered tables/cells/_employee.slim (15.6ms)
Rendered tables/cells/_employee.slim (0.0ms)
Rendered tables/_csv_data_row.haml (46.8ms)
Rendered tables/_csv_data_grid.slim (62.4ms)
Rendered tables/_csv_table.slim (156.0ms)
Rendered filters/_summary_report.haml (171.6ms)
Sent file public/excel/summary_report1393109998_178.xlsx (0.0ms)
Completed 200 OK in 312ms
2
  • Have you checked your log file to see what happens when the file is sent?
    – Ruby Racer
    Feb 22, 2014 at 22:23
  • Added log to post. "Sent 0.0ms" looks questionably. Feb 22, 2014 at 23:05

1 Answer 1

2

Are you rendering the Axlsx to a file, and then trying to send that? If so, you might have better luck with:

xlsx_package = Axlsx::Package.new(...)
# do whatever
send_data xlsx_package.to_stream.read

That should at least take care of any file permissions / path issues.

You can also use a gem like axlsx_rails, which I wrote, to create and send xlsx files. I have not, however, tested it on Windows IIS.

1
  • Yes, I used to render Axlsx to file. Your solution worked for me. Thank you very much. Feb 24, 2014 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.