Downloading Excel file xlsx in Angularjs and WebApi

后端 未结 5 790
离开以前
离开以前 2021-01-31 11:52


I am working on a task, in which I have to download a report in xlsx format. The report file is generated successfully from server, and is received on client side as well.

5条回答
  •  清酒与你
    2021-01-31 12:21

    You a just need to do one thing only that. include following js to save file locally. Download it from "https://github.com/eligrey/FileSaver.js/" your response data should be in blob type.

    I have implemented it and its working.

    function downloadfile(url,defaultFileName){
      var self = this;
        var deferred = $q.defer();
        $http.get(url, { responseType: "blob" }).then(
           function (data){
              saveAs(data.data, defaultFileName)
              deferred.resolve(defaultFileName);                    
            }, function (data) {
               var e = /* error */
                deferred.reject(e);
            });
            return deferred.promise;
    }
    

提交回复
热议问题