Amit Kumar Amit Kumar - 1 year ago 463
AngularJS Question

save excel file using FileSaver.js

I am trying to export data to excel in angular js

1) User clicks a button
2) Data in $scope.myArray gets saved to excel file.

I tried

var blob = new Blob($scope.myArray , {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
saveAs(blob, "Report.xls");

It prompts to open the excel file.
But whenever I try to open it, it says the file format or file extension is not valid.

Any Help!

Answer Source

Try this

var myJsonString = JSON.stringify($scope.myArray);
        var blob = new Blob([myJsonString], {
            type: "application/;charset=charset=utf-8"
        saveAs(blob, "Report.xls");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download