How to Converting data from Xlsx to Json, in Web Workers #2962

Closed
opened 2023-06-08 14:29:41 +00:00 by dedaMazai · 3 comments

Hello, I'm converting big data from xlsx to json, as a result of which the interface freezes, when trying to take out the XLSX.utils.sheet_to_json process in webWorker, an error occurs: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'call')

Hello, I'm converting big data from xlsx to json, as a result of which the interface freezes, when trying to take out the XLSX.utils.sheet_to_json process in webWorker, an error occurs: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'call')
Owner

For very large datasets:

  1. use the option dense: true when reading the file https://docs.sheetjs.com/docs/demos/bigdata/stream#dense-mode

  2. use stream.to_json instead of converting everything at once. The current live demo uses stream.to_csv (https://docs.sheetjs.com/docs/demos/bigdata/stream#live-demo) but you can adapt that to use to_json instead.

If the browser still locks up, the file may be too large for the current techniques. Do you have an estimate for the file size and the number of rows/columns/text cells/numeric cells?

For very large datasets: 1) use the option `dense: true` when reading the file https://docs.sheetjs.com/docs/demos/bigdata/stream#dense-mode 2) use `stream.to_json` instead of converting everything at once. The current live demo uses `stream.to_csv` (https://docs.sheetjs.com/docs/demos/bigdata/stream#live-demo) but you can adapt that to use `to_json` instead. If the browser still locks up, the file may be too large for the current techniques. Do you have an estimate for the file size and the number of rows/columns/text cells/numeric cells?
Author

The file size is 10+ MB, your solution helped me, but there was a problem with the XLSX.WriteFile method, which does not work in Web Worker

The file size is 10+ MB, your solution helped me, but there was a problem with the XLSX.WriteFile method, which does not work in Web Worker
Owner

writeFile does not work in a web worker. https://docs.sheetjs.com/docs/demos/bigdata/worker#creating-a-local-file

XLSX.writeFile will not work in Web Workers! Raw file data can be passed from the Web Worker to the main browser context for downloading.

The "Creating a local file" example in the docs includes a live example

`writeFile` does not work in a web worker. https://docs.sheetjs.com/docs/demos/bigdata/worker#creating-a-local-file > `XLSX.writeFile` will not work in Web Workers! Raw file data can be passed from the Web Worker to the main browser context for downloading. The "Creating a local file" example in the docs includes a live example
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#2962
No description provided.