Don*_*asa 4 html javascript html-table export-to-excel sheetjs
我有以下 HTML 表格和 Javascript 函数,使用 SheetJS 解析表格,然后将它们导出到 Excel 文件。
var tablesToExcel = (function() {
return function(tables, wsnames, wbname) {
var workbook = XLSX.utils.book_new();
for (var i = 0; i < tables.length; i++) {
var ws1 = XLSX.utils.table_to_sheet(document.getElementById(tables[i]));
console.log(ws1);
XLSX.utils.book_append_sheet(workbook, ws1, wsnames[i]);
}
XLSX.writeFile(workbook, wbname);
}
})();Run Code Online (Sandbox Code Playgroud)
<table id="po-table">
<thead class="thead-dark">
<tr>
<th scope="col"> Operating Unit</th>
<th scope="col"> Rate </th>
</tr>
</thead>
<tbody>
<tr>
<td>Leyte</td>
<td>90%</td>
</tr>
</tbody>
</table>
<table id="cert-table">
<thead class="thead-dark">
<tr>
<th scope="col"> Operating Unit</th>
<th scope="col"> Rate </th>
</tr>
</thead>
<tbody>
<tr>
<td>Samar</td>
<td>100%</td>
</tr>
</tbody>
</table>
<button onclick="tablesToExcel(['po-table', 'cert-table'], ['PO', 'Cert'], 'PO Report.xls')" class="btn btn-success btn-lg mb-5" id="downloadTable" type="button"> Export as Excel</button>Run Code Online (Sandbox Code Playgroud)
预期输出应在列中显示90%,但实际上,生成的 Excel 文件的列上显示的结果是0.9。
有什么方法可以设置列格式或通过 SheetJS 禁用此自动格式设置吗?
小智 6
添加{raw: true},它将保留原始字符串
var ws1 = XLSX.utils.table_to_sheet(document.getElementById(tables[i]), {raw: true});
| 归档时间: |
|
| 查看次数: |
2376 次 |
| 最近记录: |