Optimize LuckyExcel xlsx preview conversion with Web Worker (#766)

* Optimize LuckyExcel conversion with worker

* Fallback LuckyExcel worker errors to main thread
This commit is contained in:
Spencer.Chang
2026-06-29 11:20:50 +08:00
committed by GitHub
parent 3e16ed9d3b
commit 67c6ba3b13
3 changed files with 168 additions and 59 deletions

View File

@@ -0,0 +1,54 @@
// LuckyExcel's bundled getBinaryContent reads window.XMLHttpRequest.
// Web Worker exposes XMLHttpRequest on self, so provide a minimal window alias
// before loading the UMD bundle.
self.window = self;
importScripts('./luckyexcel.umd.js');
self.console.log = function () {};
self.onmessage = function (event) {
var data = event.data || {};
var url = data.url;
var name = data.name;
if (!url) {
self.postMessage({
type: 'error',
message: '文件URL为空'
});
return;
}
try {
LuckyExcel.transformExcelToLuckyByUrl(
url,
name,
function (exportJson, luckysheetfile) {
if (!exportJson || !exportJson.sheets || exportJson.sheets.length === 0) {
self.postMessage({
type: 'error',
message: '读取excel文件内容失败!'
});
return;
}
self.postMessage({
type: 'success',
exportJson: exportJson
});
},
function (error) {
self.postMessage({
type: 'error',
message: error && error.message ? error.message : String(error)
});
}
);
} catch (error) {
self.postMessage({
type: 'error',
message: error && error.message ? error.message : String(error)
});
}
};

View File

@@ -3938,7 +3938,7 @@ var LuckySheet = /** @class */function (_super) {
_this.sheetList = allFileOption.sheetList;
_this.imageList = allFileOption.imageList;
_this.hide = allFileOption.hide;
console.log(allFileOption, 'allFileOption');
// console.log(allFileOption, 'allFileOption');
_this.dataVerificationSelectCount = allFileOption.dataVerificationSelectCount;
//Output
_this.name = sheetName;