node.js - 无法读取未定义的属性(读取 'F_OK' )

标签 node.js quasar exceljs

readFile 给出未捕获( promise 中)类型错误:无法读取未定义的属性(读取“F_OK”)

ExcelJS:^4.3.0
Node JS:v14.18.2

重现步骤

const wb = new ExcelJS.Workbook();

const fullPath = path.resolve("excelName.xlsx");
await wb.xlsx.readFile(fullPath );


const buffer = await wb.xlsx.writeBuffer();

enter image description here

最佳答案

对我来说这是这样的:

    upload(fileToUpload: File) {
      this.readFile(fileToUpload, (data) =>this.readDataFromFile(data));
    }

    private readFile(fileToUpload: File, callback) {
       const reader = new FileReader();
       let data;
       reader.onload = function () {
          data = reader.result;
          callback(data);
       }
       reader.readAsArrayBuffer(fileToUpload);
    }

    private readDataFromFile(data: any) {
       var workbook = new Excel.Workbook();
       workbook.xlsx.load(data)
         .then(workbook => {
            console.log(workbook, 'workbook instance');

             workbook.eachSheet((sheet, id) => {
                sheet.eachRow((row, rowIndex) => {
                console.log(row.values, rowIndex);
                });
             });
        });
    }

将 Excel 文件作为数组缓冲区读取,并使用 exceljs 不使用方法 readFile,而是使用 load

关于node.js - 无法读取未定义的属性(读取 'F_OK' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74016333/

相关文章:

node.js - Mongoose nodejs "Unknown modifier: $pushAll"

javascript - exceljs - 将填充应用于单元格范围

node.js - 将 Admob 移植到移动网络

javascript - Node.js:子页面找不到公共(public)静态文件夹

vue.js - 使用 Quasar (Vue) 进行服务器端输入验证

java - 我可以将类星体中的 SettableFuture 假设为光纤吗?

reactjs - 在使用 exceljs 读取后,在 react-dropzone `onDrop` 中设置状态变量

node.js - exceljs如何在不同行设置标题

javascript - 为什么 req.cookies 未定义?

Cordova:不允许加载本地资源:file:///