by deepak8 Updated: Dec 20, 2022
You can build an Excel file from an HTML table using the library's excel() function after it has been included. The following arguments are taken by the excel() function:
- this: Current context of the script
- table: HTML table element to be exported
- name: Name for the Excel file
- worksheetName: The name of the Excel worksheet ('optional'; the default is "Worksheet")
PS: Sample screenshot of the webpage and excel downloaded with it
In this solution we have created a table and exported that into excel using excellentexport script
<script src="excellentexport.js"></script> <table id="ExcelTable"> <tr> <td style="color:red">Column 1</td> <td style="color:blue">Column 2</td> <td style="color:green; font-weight:bold">Column 3</td> </tr> <tr style="color: purple"> <td>400</td> <td>500</td> <td>600</td> </tr> </table> <a download="myFile.xls" href="#" onclick="return ExcellentExport.excel(this, 'ExcelTable', 'Sheet1');">Export to Excel</a>
- Copy the code snippet and insert into a standard HTML template.
- Add the below script in the HTML
- Run the HTML to see the webpage
- Click the Export to Excel to download the table as excel
I found this code snippet by searching for "Excel formatting" in kandi. You can try any such use case!
I tested this solution in the following versions. Be mindful of changes when working with other versions.
- The solution is created in HTML5 and excellentexport v3.4.3
- The solution is tested on chrome browser
- For any support on kandi solution kits, please use the chat
- For further learning resources, visit the Open Weaver Community learning page.