SheetJS / sheetjs

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs
https://sheetjs.com/
Apache License 2.0
35.02k stars 8k forks source link

How to read large file in browser without crashing #2757

Closed kikiren closed 2 years ago

kikiren commented 2 years ago

Input is a .xlsx file of 68MB to be parsed to json, and browser crashed. Is there a better way to read large file from browser?

 const data = await this.file.arrayBuffer();
 const workbook = XLSX.read(data,{
      sheets: 0,
    }); // here is no return
 const sheetNames = workbook.SheetNames;
 const worksheet = workbook.Sheets[sheetNames[0]];
 const json = XLSX.utils.sheet_to_json(worksheet);
SheetJSDev commented 2 years ago

You can try XLSX.read(data,{ dense: true }) but it is likely that the underlying XML is beyond the string length limit.

SheetJSDev commented 2 years ago

Please test

 const workbook = XLSX.read(data,{
      sheets: 0,
      dense: true,
    });

If this still hangs, please share the file and we can take a closer look