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