Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
How can I parse a large spreadsheet file using sheetJS and stream reading?

I'm currently working on writing a prebuild script for a Nextjs project that will download some data and parse it into a json file.

I found the SheetJS package which seems to do everything I need. The issue is, the ODS file I'm trying to parse is large (40k+ records) and I'm getting the following error when trying to run my script:

'Error: Cannot create a string longer than 0x1fffffe8 characters'

I've done some reading online, and the solution seems to be 'Stream reading'.

There's an example about quarter of the way down the Sheetjs readme 'Explicitly concatenating streams' which I've used as a base to create the following code.

It's running perfectly on a small file with a single line of data in the spreadsheet, but when I try and run it with the full sized spreadsheet, I'm still getting the error.

I'm guessing I might be going wrong with the stream reading part? Any advice would be much appreciated.

var XLSX = require('xlsx');
var fs = require('fs');

var parseData = async () => {
  var file = fs.createReadStream('./data/data.ods');
  function process_RS(stream, cb) {
    var buffers = [];
    stream.on('data', function (data) {
      buffers.push(data);
    });
    stream.on('end', function () {
      var buffer = Buffer.concat(buffers);
      var workbook = XLSX.read(buffer, { type: 'buffer' });

      /* DO SOMETHING WITH workbook IN THE CALLBACK */
      cb(workbook);
    });
  }

  process_RS(file, (workbook) => {
    var data = XLSX.utils.sheet_to_json(workbook['Sheets']['Cars'], {
      range: 7,
      header: ['Make', 'Model'],
    });
    console.log(data);
  });
};

parseData();

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!