导出到 Excel,纠正 fixed 时,造成的列反复问题;
入参:表对象 id,导出时的文件名称
须要援用 xlsx 插件;
function sexportExcel(sid, sname){
// 设置以后日期
let time = new Date();
let year = time.getFullYear();
let month = time.getMonth() + 1;
let day = time.getDate();
let name = sname + "" + year +"" + month + "" + day;
let xlsxParam = {raw: true};// 转换成 excel 时,应用原始的格局
let table = document.querySelector(sid);
// 因为 element-ui 的表格的 fixed 属性导致多出一个 table,会下载反复内容,这里删除掉
var fix = table.querySelector('.el-table__fixed');
let wb ;//mytable 为表格的 id 名
if (fix) {wb = XLSX.utils.table_to_book(table.removeChild(fix),xlsxParam);
table.appendChild(fix);
} else {wb = XLSX.utils.table_to_book(table,xlsxParam);
}
let 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;
}