Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

256
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda