使用Export2Excel导出页面直接卡死
版本:renren-fast 1 |
开发环境:Chrome |
点击导出后直接卡死
import('@/vendor/Export2Excel').then((excel) => {
console.log(excel);
const tHeader = ["1","2","3",'4','5','6','7','8'];
// const key = ["brandName","name","price"];
// const data = this.getJson(key);
const data =[1,2,3,4,5,6,7,8]
console.log(tHeader,data);
excel.export_json_to_excel({
header: tHeader, //表头 必填
data:[1,2,3,4,5,6], //具体数据 必填
});
});
-
2021-09-17
我们没有使用Export2Excel,具体看看官方文档
-
2021-09-22
可以尝试xlsx插件,进行导出操作;
import XLSX from "xlsx";
import FileSaver from "file-saver";
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时,使用原始的格式
/* generate workbook object from table */
// let table = document.querySelector(sid).cloneNode(true);
let table = document.querySelector(sid);
// 因为element-ui的表格的fixed属性导致多出一个table,会下载重复内容,这里删除掉
var fix = table.querySelector('.el-table__fixed');
let wb ;//mytable为表格的id名
/* get binary string as output */
if (fix) {
wb = XLSX.utils.table_to_book(table.removeChild(fix),xlsxParam);
table.appendChild(fix);
} else {
console.log("33");
wb = XLSX.utils.table_to_book(table,xlsxParam);
}
// console.log('设置边框0');
// var sheetName = wb.SheetNames[0];
// console.log('设置边框1');
// // XSU.setBorderDefaultAll(wb,sheetName);
// console.log('设置边框2');
// for (let key in wb.Sheets.Sheet1) {
// if (Object.prototype.toString.call(wb.Sheets.Sheet1[key]) === '[object Object]'){
// //置空的表格的单元格不需要增加边框,故else的时候给单元格增加边框
// XSU.setBorderDefault(wb, sheetName, key)
// }
// }
// console.log('设置边框3');
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;
}
-
2021-09-23
@Mark 那导出excel的推荐使用什么
-
2021-09-23
我这边已经修复好了,根据百度,又额外引入了bolb.js
-
2021-12-14
@violetlength 谢谢