简体   繁体   English

由于我是 nodejs 新手,我无法使用 nodejs 在 aws lambda 的 tmp 位置创建文件

[英]As I am new to nodejs, I am Unable to create file in tmp location of aws lambda using nodejs

Error:"errorMessage": "ENOENT: no such file or directory, open '/tmp/excel.xlsx'"错误:“errorMessage”:“ENOENT:没有这样的文件或目录,打开'/tmp/excel.xlsx'”
Below is the code snippet.下面是代码片段。 Can anyone please assist on this.任何人都可以在这方面提供帮助。 NOTE: I tried in python and it is working as expected but in nodejs it's not working.注意:我在 python 中尝试过,它按预期工作,但在 nodejs 中它不工作。

// Require library
    var excel = require('excel4node');

// Create a new instance of a Workbook class
    var workbook = new excel.Workbook();

// Add Worksheets to the workbook
   var worksheet = workbook.addWorksheet('Sheet 1');
   var worksheet2 = workbook.addWorksheet('Sheet 2');

// Create a reusable style
   var style = workbook.createStyle({
  font: {
    color: '#FF0800',
    size: 12
  },
  numberFormat: '$#,##0.00; ($#,##0.00); -'
});

// Set value of cell A1 to 100 as a number type styled with paramaters of style
   worksheet.cell(1,1).number(100).style(style);

// Set value of cell B1 to 300 as a number type styled with paramaters of style
   worksheet.cell(1,2).number(200).style(style);

// Set value of cell C1 to a formula styled with paramaters of style
   worksheet.cell(1,3).formula('A1 + B1').style(style);

// Set value of cell A2 to 'string' styled with paramaters of style
   worksheet.cell(2,1).string('string').style(style);

// Set value of cell A3 to true as a boolean type styled with paramaters of style but with an adjustment to the font size.
   worksheet.cell(3,1).bool(true).style(style).style({font: {size: 14}});

   workbook.write('/tmp/excel.xlsx');


   var XLSX = require('xlsx')
   var workbook = XLSX.readFile('/tmp/excel.xlsx');enter code here
   var sheet_name_list = workbook.SheetNames;
   var xlData = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]]);
   console.log(xlData);

workbook.write('/tmp/excel.xlsx');

This is an asynchronous function, and takes a callback function as a 2nd parameter.这是一个异步 function,并将回调 function 作为第二个参数。

If you want to act on this file after it writes, you must put your other logic in the callback function.如果你想在这个文件写入后对其进行操作,你必须把你的其他逻辑放在回调 function 中。 eg例如

workbook.write('/tmp/excel.xlsx', function(err, stats) => {
  // err would be the error from the interior fs.writeFile
});

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

相关问题 为什么我无法使用 NodeJS 代码删除数据库记录? - Why I am unable to delete a database record using a NodeJS code? 我无法运行nodejs项目 - I am unable to run nodejs project 我正在尝试发送图像数组,但无法使用nodejs在服务器中获取数据 - I am trying to send array of images but I am unable to get data in server using nodejs 我正在尝试使用 Express 和 Passport 创建 nodejs 登录系统,但出现错误 - I am trying to create a nodejs login system using Express and Passport , I am getting error 我是否在 NodeJS 中正确使用了 Repository 模式? - Am I using the Repository pattern correctly in NodeJS? 我可以在NodeJS中正确使用请求模块吗? - Am I correctly using the request module in NodeJS? 我是 nodejs 的新手,我不断收到此错误 - I am new to nodejs and i keep getting this error 我被困在nodejs集群中 - I am stuck in nodejs cluster 如果我不使用 cognito,如何使用 Nodejs 在 axios 中准确签署 AWS elasticsearch 搜索请求? - How to exactly sign AWS elasticsearch search request in axios using Nodejs if I am not using cognito? 我是 nodejs 的新手并尝试更新类别表中的类别,但它不起作用 - I am New to nodejs and trying to update a category in categories table but it is not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM