I want to write reusable code that takes an HTML table from a JSP and converts it to Excel format to be exported to the user. I want to take advantage of the HTML DOM Table Object rather than parse the HTML in Java to extract the same information. The biggest advantage to this would be inspecting each cell for checkboxes, buttons, etc. so as to remove them before writing the cells to Excel. In my mind the setup would go something like this:
HTML Table:
< a href="javascript: export();">Export to Excel< /a>
< table id="exportTable">
...
< /table>
JavaScript:
function export() {
var table = document.getElementById("exportTable");
// Send table object to Servlet somehow
}
The JavaScript would go in some sort of common.js so that the concept could be used on any table in any page of the site.
** UPDATE **
JSPs will be using Java objects to generate the table, but the table itself will be different every time. I'm looking for a generic solution whereby I can get the Table's DOM structure, thereby utilizing the table.rows and table.cells that is already done, inspect each cell to remove tags I don't want in the Excel (such as buttons, checkboxes, etc), and write that out to the user with the response type set to excel. Does that make more sense?