简体   繁体   English

npm exceljs 无法读取任何现有文件

[英]npm exceljs is unable to read any existing file

// read from a file
const workbook = new Excel.Workbook();
await workbook.xlsx.readFile(filename);
// ... use workbook

As per the exceljs documentation, it should load the already existing file 'filename', but when I tried reading it,根据 exceljs 文档,它应该加载已经存在的文件“文件名”,但是当我尝试阅读它时,

const sheet = workbook.addWorksheet('My Sheet'); 

sheet was actually undefined. sheet 实际上是未定义的。

My concern is, is it possible to do read from and write to a file operations in ReactJS, also I came across another article我担心的是,是否可以在 ReactJS 中读取和写入文件操作,我也遇到了另一篇文章

https://stackoverflow.com/questions/49491710/can-reactjs-write-into-file#:~:text=React%20runs%20in%20browser%20so,gets%20served%20to%20the%20browser https://stackoverflow.com/questions/49491710/can-reactjs-write-into-file#:~:text=React%20runs%20in%20browser%20so,gets%20served%20to%20the%20browser

that suggest it is not possible这表明这是不可能的

My project did read and write on the same file template using exceljs in node js.我的项目确实在节点 js 中使用 exceljs 在同一个文件模板上读写。 Hope can help you.希望能帮到你。

workbook.xlsx.readFile(template)
  .then(function () {
    // machines
    var wsMachine = workbook.getWorksheet('No');
    wsTemplate = _.cloneDeep(wsMachine);
    for (var index = 1; index <= 10; index++) {
      var copySheet = workbook.addWorksheet('No' + index, { state: 'visible' });
      copySheet.pageSetup.printArea = 'A1:FE219';
      var ws = _.cloneDeep(wsTemplate);
      copySheet.model = Object.assign(ws.model, {
        mergeCells: ws.model.merges
      });
      copySheet.name = 'No' + index;
    }

    wsMachine.state = 'hidden';
    wsTemplate.state = 'hidden';
    return workbook.xlsx.writeFile(urlOutput);
  })
  .then(function () {
    return true
  })
  .catch(function () {
    return false;
  });

Happy code快乐代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将现有的 CRA 应用程序发布到 npm(any) 存储库? - How to publish existing CRA application to npm(any) repository? npm 无法从 JSON 文件安装软件包 - npm Unable To Install Packages From JSON File 在npm中找不到模块 - Unable to find module in npm 从“exceljs”导入Excel在浏览器上抛出错误TypeError:无法读取未定义的属性“prototype” - import Excel from “exceljs” throwing error on browser TypeError: Cannot read property 'prototype' of undefined 当我尝试 npm 安装或 npm 安装时<any-package> ,我看到“无法读取 null 的属性(读取‘edgesOut’)”并且 İ 有 package.json</any-package> - When i try to npm install or npm install <any-package>, i see "Cannot read properties of null (reading 'edgesOut')" and İ have package.json 是什么阻止我安装 npm 软件包,请检查代码并告诉我。 无法安装任何库 - What is stopping me from installing npm packages please check the code and tell me. Unable to install any library 无法在 Vite 清单中找到文件:resources/js/app.jsx。 (npm 运行构建) - Unable to locate file in Vite manifest: resources/js/app.jsx. (npm run build) 无法进口合同。 JSON文件未被读取 - Unable to import contract. JSON file not being read 无法从 npm 安装 reactstrap - Unable to install reactstrap from npm 无法使用 npm 安装 Recharts - Unable to install Recharts using npm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM