Export Html Table To Excel Spreadsheet using jQuery - table2excel

File Size: 51 KB
Views Total: 627161
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Export Html Table To Excel Spreadsheet using jQuery - table2excel

table2excel is a simple yet useful jQuery plugin which allows for exporting Html table data to an Excel file.

Alternative plugins:

See also:

How to use it:

1. Include jQuery library and the jQuery table2excel plugin in the Html document.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="src/jquery.table2excel.js"></script>

2. Create an 'Export' button to export table data to an Excel file manually. Optional.

<button>Export</button>

3. Call the plugin on the table and pass the following options.

$("button").click(function(){
  $("#table2excel").table2excel({
    // exclude CSS class
    exclude: ".noExl",
    name: "Worksheet Name",
    filename: "SomeFile", //do not include extension
    fileext: ".xls" // file extension
  }); 
});

4. Then you can add the CSS class 'noExl' to any tr tags to ignore the specified table data while exporting.

<tr class="noExl">
  <th>#</th>
  <th>Column heading</th>
  <th>Column heading</th>
  <th>Column heading</th>
</tr>

5. Determine whether to preserve the background and font colors. Default: false.

$("#table2excel").table2excel({
  exclude: ".noExl",
  name: "Worksheet Name",
  filename: "SomeFile",
  fileext: ".xls",
  preserveColors: true
}); 

6. Determine whether to exclude images, links, and input fields. Default: true.

$("#table2excel").table2excel({
  exclude: ".noExl",
  name: "Worksheet Name",
  filename: "SomeFile",
  fileext: ".xls",
  exclude_img: true,
  exclude_links: true,
  exclude_inputs: true
}); 

Changelog:

2019-06-04

  • Added support for background colors and font colors in rows and columns.

2019-02-07

  • v1.1.2: Update jquery.table2excel.js

2017-05-26

  • v1.1.1: Update jquery.table2excel.js

2016-03-08

  • Support unicode and file extension feature.

2015-05-22

  • Update jquery.table2excel.js

2015-04-08

  • Added IE11 support

2015-04-04

  • Changes made to move toward supporting multiple tables to single Excel file.

This awesome jQuery plugin is developed by rainabba. For more Advanced Usages, please check the demo page or visit the official website.