I am trying to export a html table to an Excel document via a javascript/jquery export. I so far have found 2 solutions but neither meet my requirements:
- Does not export inline styling (styling is a must-have requirement)
- Does not work in all IE versions (need all browser compatibility)
I am looking for a solution that is as minimal as possible (both of these solutions were very "tidy" but as per my comments above they both had a downfall that fell short of my requirements.
Does anyone know a better solution? My requirements for this export are:
- Needs to work on all browsers
- Needs to export the inline styling
- IF POSSIBLE it would be nice to be able to name the file
Would appreciate any assistance here, pulling my hair out as I can't be the first person that has required this feature...
Thanks!
I'm assuming that PHP / Flash is a no go. (If not, checkout PHPExcel and DataTables' export feature.)
Also, naming the file is nigh impossible without server-side programming of some type. I'm pretty sure this is a security problem for most browsers.
Before we get to the code, some limitations:
tableToExcel()
function.It accepts a string of HTML table text (include
<table>
). You can format that HTML with inline styles (won't work with a CSS stylesheet unfortunately).tableToExcel($('table').html(),'Worksheet Name');
Here's the functions. Enjoy!