I need a service to download an excel file from Amazon S3, then parse with node-xlsx
The problem is that I can\'t get xlsx to parse the file. When I try to read back
Another way of doing this is using exceljs
const AWS = require('aws-sdk');
const Excel = require('exceljs');
async function downloadFile(){
AWS.config.update({
accessKeyId: AMAZON_ACCESS_KEY,
secretAccessKey: AMAZON_SECRET_ACCESS_KEY,
});
const s3 = new AWS.S3();
const stream = await s3.getObject({ Bucket: 'yor_buket', Key: 'file_name'}).createReadStream();
return stream;
}
async function loadWorkbook(stream){
return new Promise((resolve, reject) = > {
let rows = [];
const workbook = new Excel.Workbook();
workbook.xlsx.read(stream).then(function(workbook){
const worksheet = workbook.getWorksheet('sheet_name');
worksheet.eachRow({ includeEmpty: false}, function(row) {
rows.push(row.values);
});
});
resolve(rows);
});
}
async function loadFromS3(){
const stream = await downloadFile();
const dataRows = await loadWorkbook(stream);
console.log(dataRows);
}