[英]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.