SheetJS js xlsx-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);
}
})();
<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>

预期输出应该在列中显示90%,但实际上,生成的excel文件在列上显示的结果是0.9

有什么方法可以格式化列或通过SheetJS禁用这种自动格式化吗?

添加{raw:true},它将保留原始字符串

var ws1=XLSX.utils.table_to_sheet(document.getElementById(tables[i](,{raw:true}(;

最新更新