import FileSaver from "file-saver";
import XLSX from "xlsx";
exportExcel(xlsxName, className, widths) {
let fix = document.querySelector(`.${className}`).querySelector('.el-table__fixed')
let fixRight = document.querySelector(`.${className}`).querySelector('.el-table__fixed-right')
let wb;
if(fix||fixRight){
let fixedCol = fix||fixRight
wb = XLSX.utils.table_to_book(document.querySelector("." + className).removeChild(fixedCol),{raw:true});
document.querySelector("." + className).appendChild(fixedCol);
}else{
wb = XLSX.utils.table_to_book(document.querySelector("." + className),{raw:true});
}
let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
try {
FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), xlsxName);
} catch (e)
{
if (typeof console !== 'undefined')
console.log(e, wbout)
}
return wbout
}
使用
exportExcel() {
if (this.tableData.length == 0) {
this.$showAlert.showPopMsg("当前数据为空,不可导出")
return;
}
let arr = [];
let { iyear, imonth } = this.searchForm;
for (let i = 0; i < 7; i++) {
arr.push({ wpx: 100 })
}
this.$exportExcel(`${iyear}-${imonth}按路演资料划分-${this.tableData[0].mount}.xlsx`, "roadshowDataComppp", arr);
},
|