0%

Html Table Export To Excel By Vanilla JS

Here is a simple way to export the html table to excel file, you can use the following code to export the table to excel file. Thanks for the author of this library

Include the JS file

1
2
3
4
5
6
7
8
9
<script src="https://rusty1s.github.io/table2excel/dist/table2excel.js"></script>

<script>
var table2excel = new Table2Excel();

document.getElementById('export').addEventListener('click', function() {
table2excel.export(document.getElementById('table_export'));
});
</script>

Html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<table id="table_export">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>25</td>
<td>[email protected]</td>
</tr>
<tr>
<td>Mary</td>
<td>28</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
<button id="export">Export to Excel</button>

You can download the zipped js file here