javascript export to excel Example

javascript export to excel: Learn how to import and export Excel files, and provide users with an interface to interact with those files, all in pure JavaScript Source code.

A quick JavaScript library to create export to Excel/CSV from HTML tables in the browser.

javascript export to excel

Export HTML Table Data to Excel using JavaScript : How in javascript export html table data into excel (.xslx). Easily convert HTML table data, into an excel file.

Steps to export HTML table to excel using JavaScript

HTML Markup: index.html
Add table with data and button tag.

<table id="tbl_exporttable_to_xls" border="1">
		<th>Job Profile</th>
			<td><p>Kishan Tala</p></td>
			<td>Laravel Devloper</td>
			<td><p>Mayur Dhameliya</p></td>
			<td>AngularJS Devloper</td>
			<td><p>Rekha Talpada</p></td>
			<td>PHP Devloper</td>
<button onclick="ExportToExcel('xlsx')">Export table to excel</button>

Download and Import SheetJS Library on our webpage

<script type="text/javascript" src="[email protected]/dist/xlsx.full.min.js"></script>

JavaScript code

Using Sheetjs library export table data into an excel file.

function ExportToExcel(type, fn, dl) {
       var elt = document.getElementById('tbl_exporttable_to_xls');
       var wb = XLSX.utils.table_to_member(elt, { sheet: "sheet1" });
       return dl ?
         XLSX.write(wb, { memberType: type, memberSST: true, type: 'base64' }):
         XLSX.writeFile(wb, fn || ('MySheetName.' + (type || 'xlsx')));

Example 2: Export HTML Table Data to Excel using JavaScript

Export HTML Table Data to Excel

function exportTableToExcel(tableID, docname = ''){
    var fourceDLink;
    var dataType = 'application/';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
    docname = docname?docname+'.xls':'excel_data.xls';
    fourceDLink = document.createElement("a");
        var blob = new Blob(['\ufeff', tableHTML], {
            type: dataType
        navigator.msSaveOrOpenBlob( blob, docname);
        fourceDLink.href = 'data:' + dataType + ', ' + tableHTML;
    = docname;


<table id="memberInfo">
        <td>Krishna Dave</td>
        <td>[email protected]</td>
        <td>Jagruti Bhavshdiya</td>
        <td>[email protected]</td>
        <td>Hitesh Ajera</td>
        <td>[email protected]</td>

<button onclick="exportTableToExcel('memberInfo')">Export Table Data To Excel File</button>
<button onclick="exportTableToExcel('memberInfo', 'members-data')">Export Table Data To Excel File</button>

Don’t Miss : JavaScript export to Excel with formatting

Also Read This ๐Ÿ‘‰   List of JavaScript Objects and Functions with Example

I hope you get an idea about javascript export to excel.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.