In this article I will explain with an example, how to download Excel file (XLS and XLSX) using jQuery.
The HTML Table data will be converted and downloaded to Excel file with the help of the jQuery table2excel plugin.
HTML Markup
The following HTML Markup consists of an HTML Table and a Button.
<table id="tblCustomers" cellspacing="0" cellpadding="0">
        <th>Customer Id</th>
        <td>John Hammond</td>
        <td>United States</td>
        <td>Mudassar Khan</td>
        <td>Suzanne Mathews</td>
        <td>Robert Schidner</td>
<br />
<input type="button" id="btnExport" value="Export" />
<script type="text/javascript" src=""></script>
<script src="table2excel.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $("#btnExport").click(function () {
                filename: "Table.xls"
When the Export Button is clicked, the jQuery table2excel plugin is applied to the HTML Table. The jQuery table2excel plugin accepts filename parameter which sets the name of the Excel file.
Note: You will get a Warning message from Microsoft Excel application when you try to open the generated Excel file. This Warning is shown because the generated file is not a valid Excel format as the plugin simply exports the HTML content to an Excel file.
The HTML Table
Download Excel File (XLS and XLSX) using jQuery
Excel file being downloaded when Export Button is clicked
Download Excel File (XLS and XLSX) using jQuery
The generated Excel file
Download Excel File (XLS and XLSX) using jQuery
Browser Compatibility

The above code has been tested in the following browsers.

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.