Uncaught RangeError:Invalid array length when export just 80000 rows json data to .xlsx file #3294

Open
opened 2025-03-22 03:36:17 +00:00 by lalason · 3 comments

here is the error

Uncaught RangeError: Invalid array length
    at Array.push (<anonymous>)
    at utf8write (xlsx.mini.js:2979:22)
    at zip_add_file (xlsx.mini.js:2830:116)
    at write_zip (xlsx.mini.js:7859:4)
    at write_zip_type (xlsx.mini.js:8041:10)
    at writeSync (xlsx.mini.js:8145:22)
    at Object.writeFileSync (xlsx.mini.js:8168:9)
    at saveJsonToExcel (NCCData.aspx:191:18)
    at NCCData.aspx:124:25
    at jRequest.Send_For_JSON (script.js:160:24)`

here is my code

        function saveJsonToExcel(jsonData, fileName) {
            var wb = XLSX.utils.book_new();
            var ws = XLSX.utils.json_to_sheet(jsonData);
            XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
            XLSX.writeFile(wb, fileName);
        }

seems error happens while doing the writeFile step

here is the error ``` Uncaught RangeError: Invalid array length at Array.push (<anonymous>) at utf8write (xlsx.mini.js:2979:22) at zip_add_file (xlsx.mini.js:2830:116) at write_zip (xlsx.mini.js:7859:4) at write_zip_type (xlsx.mini.js:8041:10) at writeSync (xlsx.mini.js:8145:22) at Object.writeFileSync (xlsx.mini.js:8168:9) at saveJsonToExcel (NCCData.aspx:191:18) at NCCData.aspx:124:25 at jRequest.Send_For_JSON (script.js:160:24)` ``` here is my code ```js function saveJsonToExcel(jsonData, fileName) { var wb = XLSX.utils.book_new(); var ws = XLSX.utils.json_to_sheet(jsonData); XLSX.utils.book_append_sheet(wb, ws, 'Sheet1'); XLSX.writeFile(wb, fileName); } ``` seems error happens while doing the writeFile step
Owner

Can you share the dataset? If not, can you check the value of ws["!ref"] before the writeFile call?

Can you share the dataset? If not, can you check the value of `ws["!ref"]` before the `writeFile` call?
Author

Can you share the dataset? If not, can you check the value of ws["!ref"] before the writeFile call?

ws["!ref"] value is A1:AX116524 ,should be in the range.

can't share dataset, and I try other dataset still have this problem. It works well when rows no more than 30000-40000 and error when few more rows. Maybe It is buffer problem. Anyway I try some other backend solution when dataset is big.thanks

> Can you share the dataset? If not, can you check the value of `ws["!ref"]` before the `writeFile` call? ws["!ref"] value is A1:AX116524 ,should be in the range. can't share dataset, and I try other dataset still have this problem. It works well when rows no more than 30000-40000 and error when few more rows. Maybe It is buffer problem. Anyway I try some other backend solution when dataset is big.thanks
Owner

Can you try forcing dense mode?

        var ws = XLSX.utils.json_to_sheet(jsonData, {dense: true});
Can you try forcing [`dense` mode](https://docs.sheetjs.com/docs/demos/bigdata/stream#dense-mode)? ```js var ws = XLSX.utils.json_to_sheet(jsonData, {dense: true}); ```
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#3294
No description provided.