How do I download contents of an html table generated by play 1.2.7 backend on java in xls

I've generated a table using play's #{list} tag and get pretty decent results. Now I need to be able to generate and download an xls version of the table and have no idea what to do. Any pointers at all will be much appreciated

Upvotes: 2

Views: 880

Answers (1)

Alan Hay
Alan Hay

Reputation: 23246

Well you have various options.

Excel will open HTML files. So instead of rendering your table as HTML you can it to stream it to the browser and set the content type as XLS.

While Excel will open it this it will still be an HTML file rather than an XLS(X) document.

You can generate as CSV from your data model and stream this to the browser. Again this will be a CSV rather than a proper XLS(X) document.

There also seem to be some solutions around which can do it using Javscript. See as a starting point: Generate excel sheet from html tables using jquery

Finally you can can use something like Apache POI or JXLS to generate a 'proper' xls(x) document and stream this to the browser. I have some code here that will export HTML to 'proper' xlsx file if this is the route you wish to go. Workflow is then to create some HTML from your data model and use this to convert to Excel rather than having to programmatically build the Excel document using POI. https://github.com/alanhay/html-exporter

Upvotes: 1

Related Questions