When I try to edit the excel file and upload it to the server, it writes the file but when I try to open it I get an error message "We found a problem with some content .xlsx error"
const uploadAttachment = async (arrayAttach) => {
try {
let sftp = new Client();
await sftp.connect(config)
const promises = arrayAttach.map(async attachment => {
const workbook = new Excel.Workbook();
await workbook.xlsx.load(attachment.buffer);
workbook.worksheets[0].name = 'sheet1';
const buffer = await workbook.xlsx.writeBuffer();
sftp.put(buffer, `test/${attachment.originalname}.xlsx`);
});
Promise.all(promises)
.then(results => {
console.log('all files have been uploaded');
})
.catch(e => {
logger.error(e)
console.error(e);
});
} catch (err) {
logger.error(err)
console.log(err);
}
}
But if I upload the file to the server without editing it I get it right, I attached a sample code
const uploadAttachmentOld = async (arrayAttach) => {
try {
let sftp = new Client();
await sftp.connect(config)
const promises = arrayAttach.map(async attachment => {
logger.info(attachment)
sftp.put(attachment.buffer, `test/${attachment.originalname}.xlsx`);
});
Promise.all(promises)
.then(results => {
console.log('all files have been uploaded');
})
.catch(e => {
console.error(e);
});
} catch (err) {
console.log(err);
}
}
I would love if someone could help me understand where my mistake is