Node.js: Fetch + pipe with excel not working

让人想犯罪 __ 提交于 2020-12-15 01:45:40

问题


I am trying to read the contents of excel and write it into another excel. But may be i am missing something. here is relevant part of my code

      await fetch(fetchUrl)
        .then(
          res =>
          new Promise((resolve, reject) => {
            const dest = fs.createWriteStream("./text.xlsx");
            res.body.pipe(dest);
            res.body.on("end", () => resolve("it worked"));
            dest.on("error", reject);
          })
        )
        .then(x => console.log(x));

I get the following alert if i try to open the file

Excel cannot open the file ’text.xlsx’ because the file format or file extension is not valid. Verify 
that the file has not been corrupted and that the file extension matches the format of the file.

Any help as to what i am missing will be really great. Thanks.

来源:https://stackoverflow.com/questions/65254633/node-js-fetch-pipe-with-excel-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!