Closed simyara closed 1 year ago
Hi @simyara, take a look at this thread from SheetJS, which is the module in use under the hood here.
hei i think the best soution is to use workers m using react but when i tried workers browser no longer freezez @simyara
const createWorker = () => {
const blob = new Blob(
[
`
importScripts('https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js');
self.onmessage = async function(e) {
try {
const file = e.data;
const data = await file.arrayBuffer();
const workbook = XLSX.read(data, { type: 'array' });
const worksheet = workbook.Sheets[workbook.SheetNames[0]];
const jsonData = XLSX.utils.sheet_to_json(worksheet, {
header: 1,
defval: "",
});
self.postMessage({ status: 'success', data: jsonData });
} catch (error) {
self.postMessage({ status: 'error', error: error.message });
}
};
`,
],
{ type: "application/javascript" }
);
return new Worker(URL.createObjectURL(blob));
};
read excel file
const readExcel = (file) => {
return new Promise((resolve, reject) => {
const worker = createWorker();
worker.onmessage = function (e) {
if (e.data.status === "success") {
resolve(e.data.data);
} else {
reject(new Error(e.data.error));
}
worker.terminate();
};
worker.onerror = function (e) {
reject(new Error(e.message));
worker.terminate();
};
worker.postMessage(file);
});
};
When file has 461k of rows (single sheet)
excelToJson
works well, but for file with 469k+ of rowsexcelToJson
returns empty array.