eligrey / FileSaver.js

An HTML5 saveAs() FileSaver implementation
https://eligrey.com/blog/saving-generated-files-on-the-client-side/
Other
21.61k stars 4.38k forks source link

Download excel file #636

Open gutofurlan opened 4 years ago

gutofurlan commented 4 years ago

I put the following code to get the result of my axioss and save an excel.

saveAs(new Blob(data), 'dddddd.xlsx', {type: "text/vnd.ms-excel;charset=utf-8"});

However when opening excel it says that the file is corrupted. Can anybody help me

zeeshansarwar38 commented 4 years ago

Try this: saveAs(new Blob([data],{type: "text/vnd.ms-excel;charset=utf-8"}), 'dddddd.xlsx')

JulianoGTZ commented 4 years ago

@zeeshansarwar38

In the instance of your Blob there, maybe you need to define the charset.

const BOM = '\uFEFF';
const csvArray += BOM;
const blob = new Blob([csvArray], { type: "text/csv;charset=utf-8" })

This way you define in the blob itself the charset to add the character relative to the BOM.