Corrupt XLSX file after downloading
See original GitHub issueHi, I know there is already a very similar issue here but it does not provide a solution, because the author of this issue just uses a different approach to download the file in the end. https://github.com/SheetJS/js-xlsx/issues/122
I’m trying to download a file which is generated in the nodejs backend from the angular frontend, but when I try to open it, it’s always corrupted. Of course I have seen the example in the readme of this project and tried it, but it also came out corrupted. I can write the output to a file and then point the browser to it by using window.location() and the file is fine. Sadly I could not get this approach working with my authorization code. I read somewhere that it’s better to send buffer objects when working with expressjs, so here is my code right now:
// Backend
var wopts = { bookType:'xlsx', bookSST:false, type:'buffer' };
var wbout = XLSX.write(workbook,wopts);
res.writeHead(200, [['Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']]);
res.end( wbout );
// Frontend
// This triggers the backend function:
$http.get("/abrechnung/exportToExcel/" + JSON.stringify(pageAndFilter.filterByFields)).
success(function(data, status, headers, config) {
// The data object is the buffer
saveAs(new Blob([data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}), "test.xlsx");
}).
error(function(data, status, headers, config) {
});
Any help would be greatly appreciated!
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:27 (6 by maintainers)
Top GitHub Comments
Ok. Sorry for the monologue but I solved it: In the frontend when making the GET Request, the Response Type has to be set to arraybuffer like this:
I think this is actually an issue in angularJS and has nothing to do with this project. Thank you anyways!
I hope this helps! Feel free to use or edit it as you wish