0

I am trying to read from a excel file and generate a copy of it / write to another excel file.

I have been able to read the file correctly and create a buffer object out of it, below is the relevant part of my code.


          let fn = `writeToStream_${Date.now()}`;
          await page.exposeFunction(fn, async (body, done) => {
            let buffer = Buffer.from(body, config.get('encoding'));
            //await writeStream.xlsx.write(buffer);  //Not sure what to do here??
          });

          const fetchDataResp = await page.evaluate(async (fn, fetchUrl, requestTimeout, enc) => {
              const fetchPromise = fetch(fetchUrl, {signal});
              const stream = await fetchPromise;
              let reader = stream.body.getReader();
              const decoder = new TextDecoder();
              while(true) {
                const {done, value} = await reader.read();
                if (done){
                  break;
                }
                let v = decoder.decode(value, {stream: true, ignoreBOM: false});
                await window[fn](v, false);
              }
              await window[fn]("", true);
              return receivedLength;
          },fn,fetchUrl,config.get('export_generator'), config.get('encoding'));

I am not sure how to proceed with creating a excel file out of this. Any help would be really great, Thanks.

opensource-developer
  • 2,826
  • 4
  • 38
  • 88

1 Answers1

0

Just a quick thought - maybe not the in-depth answer you're looking for, but maybe having the data as a TSV (or CSV) format/file might be simple enough for your needs (?); e.g. not really have a direct reliance upon Excel / putting the emphasis upon Excel to do (at least some of) the hard-graft for you (- in it 'Export'ing to the generic format on your behalf).

'EPPlus' is a decent library; maybe this link might be of some interest:

https://andriybuday.com/2016/02/working-with-excel-files-using-epplus-and-xlsx-js.html

DennisVM-D2i
  • 416
  • 3
  • 8