Hi friend in this page we know about how to conver Html table into the excel with help of javascript library.
Step 1:-
Add Create table
<table id="table">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
<br />
<br />
<button onclick="convert('xlsx')">Export</button>
Step 2:-
Add Java Script CDN
<script src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
Step 3:-
Write javascript code
<script>
function convert(type, fn, dl) {
var table = document.querySelector("#table");
var wb = XLSX.utils.table_to_book(table, { sheet: "sheet1" });
return dl ?
XLSX.write(wb, { bookType: type, bookSST: true, type: "base64" }) :
XLSX.writeFile(wb, fn || "SheetName." + (type || xlsx));
}
</script>
Thank For Visiting my Blog Site.
Post a Comment