I'm making a payroll generator system and i don't know how to export the designed payroll html file to a excel file? Can someone help me what i have to do or to use?
CodePudding user response:
You can use the awesome plugin that call Datatables , the plugin allows us to export the HTML table data into Excel,PDF ,TEXT. Thats easily configurable.
Or you can try to use this simple function
function exportPdf(elem) {
//select your table first
const table = document.getElementById("table");
const html = table.outerHTML;
const url = 'data:application/vnd.ms-excel,' escape(html); // Set your html table into url
elem.setAttribute("href", url);
elem.setAttribute("target", "__blank");
elem.setAttribute("download", "export.xls"); // Choose the file name
return false;
}
and call the function to a link
<a onclick="exportPdf(this)">Export to excel</a>
CodePudding user response:
You just need a simple function to do it:
Here an example: https://www.revisitclass.com/css/how-to-export-download-the-html-table-to-excel-using-javascript/