Closed AutomataVM closed 4 years ago
I am having a similar issue, but I am using node mailer to email the excel sheet that gets generated, its showing that the file is corrupt. So I am also looking around for possible solutions and help.
I managed to solve it by myself, here's what I did
server side: wb.writeToBuffer().then((buffer) => { const binaryBuffer = Buffer.from(buffer); res.attachment('Spreadsheet.xlsx'); return res.status(200).send({status:'ok',file:binaryBuffer}); });
client side:
function toArrayBuffer(buf) { var ab = new ArrayBuffer(buf.length); var view = new Uint8Array(ab); for (var i = 0; i < buf.length; ++i) { view[i] = buf[i]; } return ab; } var file = data.file;
var blob = new Blob([toArrayBuffer(file.data)],{type:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'reporte.xlsx';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
Thanks @juanpablo64 do we want to close this and mark it resolved :)
When I download the data on the client, I always receive the "this excel is corrupted" message. The filesize is also different and I do not know why.
To Reproduce on the server:
on the client (angular js 1)
Expected behavior I want to download a clean excel file with the contents as generated on the server
Environment (please complete the following information):