How to Convert HTML Table to Excel Using jQuery

Last Updated on August 17, 2022 by Roshan Parihar

In this tutorial, learn how to convert HTML table to excel sheet in jQuery. The short answer is the use the jQuery plugin ‘table2excel’ to export the HTML table content into excel format.

There can be many other useful methods for allowing users to download the table data to their local system in excel format. Let’s find out with the examples given below.

How to Convert HTML Table to Excel Using jQuery

To convert your tabular form data into an excel spreadsheet, the jQuery ‘table2excel’ plugin is the easiest method to include in your project. You just have to use a simple script to create downloads for your users in excel format.

Firstly, you have to include the jQuery library ‘jquery.min.js’ in your project. After that, include the plugin JS file with the name ‘jquery.table2excel.js’ as given below.

Output

Sr No. Cricket Name Country Score
1 Sachin Tendulkar India 132*
2 Virat Kohli India 169
3 Jonny Bairstow England 102*
4 Rohit Sharma Tendulkar India 132*
5 David Warner Australia 151*



Click the above button to export the table in excel spreadsheet format

It also requires including a small script just below the table and button. The script contains the click event on the button element and the table selector using table id. After that, use the table2excel() within which specify the file name and the extension ‘.xls’.

Exclude Table Rows or Cells From the Excel Sheet Using jQuery

If you want to exclude table cells from the excel export file, you have to specify the class to the cells and add a line to the small script as exclude: ".yourclassname". This will exclude the cells that contain the specified classes.

Output

Sr No. Cricket Name Country Score
1 Sachin Tendulkar India 132*
2 Virat Kohli India 169
3 Jonny Bairstow England 102*
4 Rohit Sharma Tendulkar India 132*
5 David Warner Australia 151*



Click the above button to export the table in excel spreadsheet format

When you click the button given above, you will get the download in excel format with a table excluding the cell with the specified class.

So, ‘table2excel’ is the simple jQuery plugin to easily convert your HTML tables into excel format downloads.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.