Reputation: 1197
I have a Java application where reports are generated dynamically in the form of tables. I need to have a button on a webpage whereby clicking on it will export the table to Excel. The table has to be saved by the user at the client side. How can I achieve this functionality? Will Apache POI API be helpful?
Upvotes: 0
Views: 2450
Reputation: 3446
In the meantime there's also a client-side library (XLSX.js) available. Might be handy when you use something like datatables with client-side filtering and ordering.
Upvotes: 1
Reputation: 2388
Also consider writing an HTML-format table (Excel can read that, too, including better formatting than CSV).
And, check out JExcelAPI, which I think is really easier to use than POI.
Upvotes: 0
Reputation: 22822
I used POI successfully in the past, but it has its quirks. The best way I've used it is to have a "template" file with all your formatting, colouring, etc. in your server, and copy and populate it with your data when exporting.
But if your data is a simple column-separated table, and you don't worry yoo much about formatting and data types, why not exporting the data in plain text? (CSV format) This can be opened by Excel, and will be far more efficient in term of speed an memory usage when exporting your data.
It will also bit a lot simpler to generate, you can use your own POJO generator, which will be a lot easier to test.
Use POI only if your users expect dedicated date format or distinction between Integer / Text cells. Or if you need dynamically calculated cells (using formulas) If not, you can export everything as Strings, and Excel will find its way when opening the csv file.
Upvotes: 1
Reputation: 4185
Some of my colleagues have used POI api for exporting really big reports. I think now it is the best one.
Upvotes: 0