首页 > 解决方案 > Node.js:使用 excel 获取 + 管道不起作用

问题描述

我正在尝试读取 excel 的内容并将其写入另一个 excel。但可能是我错过了一些东西。这是我的代码的相关部分

      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));

如果我尝试打开文件,我会收到以下警报

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.

关于我所缺少的任何帮助都会非常棒。谢谢。

标签: javascriptnode.jsfetch-api

解决方案


推荐阅读