I'm using exceljs with Typescript in my project. But writeBuffer() function returns ExcelJS.Buffer instead of Buffer type. And since ExcelJS.Buffer inherits from ArrayBuffer, converting ArrayBuffer to Buffer will break excel file. Does anyone have a solution to this problem?
Thanks in advance!
declare interface Buffer extends ArrayBuffer { }
let resultExcel: Buffer; // buffer
const tmpResultExcel: ExcelJS.Buffer = await tmpWorkBook.xlsx.writeBuffer(); // arraybuffer
resultExcel = Buffer.from(tmpResultExcel); // doesn't work well
Actually, the problem with tmpWorkBook.xlsx.writeBuffer(); comes from a wrong returned type definition, in my point of view.
if you try Buffer.isBuffer(tmpResultExcel), you see that tmpResultExcel is an actual JavaScript Buffer.
You can solve the type issue with
const tmpResultExcel: any = await tmpWorkBook.xlsx.writeBuffer();
and you can use tmpResultExcel as a buffer in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With