We will learn here how how to export data to excel using JQuery , In this article you can export Gridview data or html table data into excel.
Let's start now
Step 1: Design basic HTML table as in the following snippet to make sure that table should be present under DIV element and provide an ID to that DIV element.
- <div id="content" style="width: 1200px; margin: 30px auto;">
- <table style="width:100%">
- <tr>
- <td>Jill</td>
- <td>Smith</td>
- <td>50</td>
- </tr>
- <tr>
- <td>Eve</td>
- <td>Jackson</td>
- <td>94</td>
- </tr>
- </table>
- </div>
- <input type="button" id="btn_excel" value="exportexcel"/>
Step 2 : Here comes the code to export the data into excel (jQuery).
- $("#btn_excel").click(function(e) {
- window.open('data:application/vnd.ms- excel,' + encodeURIComponent($('#content').html()));
- e.preventDefault();
- });
That's it with a single line of code we can export the data to excel.
I hope this helps u.
Happy coding!