Is there any way by which we can export an HTML table to excel using javascript. I am working on a project that requires JSON data key values to be exported as excel table cells.
If you could provide any javascript library that can do the job will be a graat help. Thanks
You can use SheetJS - https://github.com/sheetjs/js-xlsx which is a javascript library for this purpose.
It gives you multiple options to export excel in different formats like .xlsx, .xlsb, .ods, .fods, etc. Below is the simple explanation to add excel export of the table into your website.
First of all, add sheetjs library to your webpage by downloading from github link and link 'xlsx.full.min.js' to your webpage using script tag as below
OR, you can also add cdn link of sheetjs library as below
Now create a table inside your HTML code and a button on which click the export table code will be called along with the script function, below is the sample code
The full HTML code to export table can be found below
Set the headers
Hi, thanks for this code, really it was very usefull for me. But, when I want to set the headers the file show a blank row between headers and the rows.
How can I to delete this blank row? Please, can you help me please? Thanks very much. Best regards
This code I setted to the table