npm install --save xlsx file-saver
安裝這個依賴后:
exportExcel() {
/* generate workbook object from table /
var wb = XLSX.utils.table_to_book(document.querySelector("#excel"));
/ get binary string as output */
var wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array"
});
try {
FileSaver.saveAs(
new Blob([wbout], { type: "application/octet-stream" }),
"sheetjs.xlsx"
);
} catch (e) {
if (typeof console !== "undefined") console.log(e, wbout);
}
return wbout;
},
匯出的Excel數字太長變成科學計數法,請問怎么解決
uj5u.com熱心網友回復:
exportExcel() {/* 轉換成excel時,使用原始的格式,解決數字列自動轉科學計數法問題 */
let xlsxParam = { raw: true };
/* out-table關聯匯出的dom節點 */
let wb = XLSX.utils.table_to_book(document.querySelector('#out-table'), xlsxParam);
/* get binary string as output */
let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
try {
FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), 'MOS首鋪貨商品匯入失敗資料.xlsx');
} catch (e) {
if (typeof console !== 'undefined') console.log(e, wbout);
}
return wbout;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/284397.html
標籤:其他技術討論專區
上一篇:全域變數
