I’m trying to generate reports. I already created the HTML table in a view and wanted to follow the approach talked about in “Exporting data to CSV and Excel in your Rails app“.
I read:
“On my project I save the html table into a file, but give it the xls extension instead of html. e.g table.xls. I then send it to the browser with the Excel mime type, and Excel will open this file and will also format the table like the html table is, so you’ll get boldened headings and cell background colors etc.. “
“The easiest way I know is to generate an HTML file with a table and give it an XLS extension. The HTML charset is respected, you can have linebreaks as much as you want, little or big endian is not an issue, th-tags define the column-headers and there are already plenty of solutions to build the file.”
How can I save the HTML table into a file, and give it an .XLS extension to open it in Excel?
Don’t know if that’s good advice or not. Personally I always stick to csv. But here’s how you would do it.
Then in config/initializers/mime_types.rb you’ll need to append: