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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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