Save excel file with FileSaver.js

I am trying to export data to excel in angular js

1) The user clicks the button 2) The data in $ scope.myArray is saved in the excel file.

I tried

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

He suggests opening an excel file. But whenever I try to open it, it says that the file format or file extension is invalid.

Any help!

+4
source share
2 answers

try it

var myJsonString = JSON.stringify($scope.myArray);
        var blob = new Blob([myJsonString], {
            type: "application/vnd.ms-excel;charset=charset=utf-8"
        });
        saveAs(blob, "Report.xls");
+7
source
 csv = ['name','md5','desc']
  _.map $scope.trustFileList, (_file) ->
    csv.push "\n#{_file.name}"
    csv.push _file.md5
    csv.push _file.desc

  blob = new Blob([csv], {
    type: "application/json;charset=utf-8"
  });

  saveAs(blob, "TrustFileWhiteList.xls");
0
source

Source: https://habr.com/ru/post/1614247/


All Articles