如何使用格式为excel文件的html表格导出工资单



我正在制作一个工资生成器系统,我不知道如何将设计好的工资html文件导出到excel文件?有人能帮我做什么或用什么吗?

您可以使用调用Datatables的强大插件,该插件允许我们将HTML表格数据导出为Excel、PDF、TEXT。这很容易配置。

或者你可以尝试使用这个简单的功能

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;
}

并将函数调用到链接

<a onclick="exportPdf(this)">Export to excel</a>

最新更新