Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Base64 from ExcelJS WorkBook

I am working with ExcelJS library in NodeJS for creating a excel file. What I need it's to generate a Base64 string from a Workbook object.

I have this code

let workbook = new Excel.stream.xlsx.WorkbookWriter({});
let worksheet = workbook.addWorksheet(`CREReport_${origcontractid}`);
worksheet.getCell('A1').value = 'CRE evolution';
worksheet.commit(); 

but I don't know how to generate a Base64 string based on my workbook. I don't want to create a file in my disk, i want to return in my webservice a base64 string which represent the file. any idea?

Thanks!

like image 742
pbalasimon Avatar asked Apr 18 '26 07:04

pbalasimon


1 Answers

with the file buffer you can get the base64.

const fileBuffer = await workbook.xlsx.writeBuffer()
like image 109
Jorge Rolhas Avatar answered Apr 19 '26 20:04

Jorge Rolhas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!