You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
761 B
JavaScript

import FileSaver from "file-saver";
import XLSX from "xlsx";
/**
* 字符权限校验
* @param {Array} value 校验值
* @returns {Boolean}
* id:表ID
* name:导出表名字
*xlsxParamtrue/false:如果表格里有数字日期这些需要加上raw: true
*/
export function handleExport(id,name,xlsxParam) {
var wb = XLSX.utils.table_to_book(
document.querySelector('#'+id),
{raw: xlsxParam}
);
var wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array",
});
try {
FileSaver.saveAs(
new Blob([wbout], { type: "application/octet-stream" }),
name+".xlsx"
);
} catch (e) {
if (typeof console !== "undefined") {
console.log(e, wbout);
}
}
return wbout;
}