本帖最后由 冥冥中明明是你 于 2024-10-23 09:25 编辑
在导出Excel文件时报错,前端框架为vue3
如果引入 import 'file-saver',控制台报错信息为:
GET http://localhost/node_modules/.vite/deps/file-saver.js?t=1729594247436&v=87767d71 net::ERR_ABORTED 504 (Outdated Optimize Dep)
如果注释掉 import 'file-saver',则报错信息为:
{errorCode: 1, errorMessage: '文件格式错误'};
请问是什么原因?
package.json内安装依赖为:
"@grapecity/spread-excelio": "14.2.4",
"file-saver": "2.0.4",
vue页面文件内引入:
import { IO } from "@grapecity/spread-excelio"; // 导入导出模块
import 'file-saver';
导出函数代码:
function exportExcel() {
let spread = spreadRef.value;
let excelIo = new IO();
let fileName = "test.xlsx";
let password = "";
let json = spread.toJSON({ columnHeadersAsFrozenRows: true });
excelIo.save(json, function (blob) {
saveAs(blob, fileName);
}, function (e) {
console.log(e);
}, {
password: password
});
}
|