Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Large Excel Files with SheetJS/js-xlsx?

I am using this package: https://www.npmjs.com/package/xlsx

However I can have some very large excel files that could contain 1 million rows.

I tested with 600K rows which is about 15mb excel file and my code is already crashing on localhost.

Is there away to stream it in? I know the documentation says they don't have any sort of streaming api but it talks about buffering?

 var reader = new FileReader();
    reader.onload = evt => {
      const bstr = evt.target.result;
      const wb = XLSX.read(bstr, { type: "binary" });
      const wsname = wb.SheetNames[0];
      const ws = wb.Sheets[wsname];
      const data = XLSX.utils.sheet_to_json(ws, { header: "A", defval: "" });
      });
    };
    reader.readAsBinaryString(this.file);
like image 332
chobo2 Avatar asked Jul 26 '18 21:07

chobo2


People also ask

How do I unzip an XLSX file?

xlsx into an empty directory. Open a terminal window in that directory, then type: unzip your-file-name. xlsx.

Can Apache POI read XLSX?

Apache POI is able to handle both XLS and XLSX formats of spreadsheets. Some important points about Apache POI API are: Apache POI contains HSSF implementation for Excel '97(-2007) file format i.e XLS. Apache POI XSSF implementation should be used for Excel 2007 OOXML (.

How parse data from Excel to JavaScript?

This can be done quite easily using SheetJS. import { read, writeFileXLSX, utils } from "https://cdn.sheetjs.com/xlsx-0.18.7/package/xlsx.mjs"; const workbook = read(data, { type:'binary', }); data is the binary string resulting from reading an Excel file as a binary string with the FileReader API.


1 Answers

When I had to read data from a very large excel file ( about 50 mb), I converted it to csv on the backend with Excel Interop, which takes shorter time than getting data from Excel file. Then, just get the first n number of lines via stream reader. Which will give you the required data to preview. Send this to the front-end for preview. This is what I would do.

like image 74
Bibek Shah Avatar answered Oct 10 '22 06:10

Bibek Shah