I am using xlsx-populate module with node.js. I am sending the workbook as a buffer, as mentioned on their site. I am using postman to hit the API and get the xlsx file as attachment. But the response I am getting has weird characters as shown below:
�2�N��N��+xl/drawings/drawing1.xml����0��>ٻ=C���@`ChB�M�
��M���8�̗�����ً��5��2��i
const workbook = await XlsxPopulate.fromFileAsync(filename);
// await workbook.toFileAsync(outfile);
const data = await workbook.outputAsync();
res.attachment("output.xlsx");
res.send(data);
When I use await workbook.toFileAsync(outfile);
to save the file locally, everything works and I can read the file.
But when I try to send the file to download using the commands res.attachment("output.xlsx");
and res.send(data);
, I get weird characters in the response to Postman.
The response headers have 11 properties which includes:
content-disposition -> attachment; filename="output.xlsx"
content-type -> application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Similar steps to download xlsx file using express is also mentioned on the GitHub page of xlsx-populate
:
https://github.com/dtjohnson/xlsx-populate#serving-from-express
Try using the "Send and download" button in Postman, just click the up arrow on the Send button and you should see this option.
Then when you send the request you should be prompted to download the "output.xlsx" file.
I don't think you need to make any coding changes.