I have to create a new excel file from the base64 data. I'm getting base64 content from the s3 bucket and I have to save the excel file in the temp directory for further processing using node.js.
I tried converting the base64 to string using Buffer and then save to excel. Even though the file is created but it is corrupted.
I have used xlsx
and node-xlsx
npm module, but none is working.
Any lead will be appreciated.
CodePudding user response:
I'm working on a problem statement where I have to create a folder structure by reading the JSON file.
The xlsx npm module is working fine. Here in my code innerItem.fname
is filename and innerItem.content
is excel content in base64 format.
if (path.extname(innerItem.fname) === ".XLSX") {
const bf = Buffer.from(innerItem.content);
// console.log(bf.toString());
// xlsx npm const XLSX = require("xlsx");
const workbook = XLSX.read(bf.toString());
XLSX.writeFile(workbook, `${directory}/${innerItem.fname}`);
} else {
await fs.writeFile(`${directory}/${innerItem.fname}`, innerItem.content);
}