You must have exported table data to excel using server side language like ASP.NET, PHP, JSP etc. But how about exporting HTML table data to Excel using jQuery.
To export the table, use window.open() method to open Excel application and pass the table's content.
If your table HTML contain special characters, then before sending the html to excel it must be encoded.
To export the table, use window.open() method to open Excel application and pass the table's content.
window.open(MIMEtype,replace);
- MIMEtype: Optional. The type of document you are writing to. Default value is "text/html".
- replace: Optional. If set, the history entry for the new document inherits the history entry from the document which opened this document.
$("#btnExport").click(function(e) { window.open('data:application/vnd.ms-excel,' + $('#dvData').html()); e.preventDefault(); });See result below
If your table HTML contain special characters, then before sending the html to excel it must be encoded.
$("#btnExport").click(function(e) { window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#dvData').html())); e.preventDefault(); });
See Complete Code
Feel free to contact me for any help related to jQuery, I will gladly help you.
No comments:
Post a Comment