Home > Article > Web Front-end > AngularJS uses webApi to export data
This article mainly shares with you AngularJS using webApi to export data code examples. I hope the code in this article can help everyone.
/////导出功能 self.importExcel = function () { var dataUrl = "http://103.233.7.38:8090/API/_oa/ProjectInfo.asmx/Export"; $http({ method: 'post', url: dataUrl, data: { }, transformRequest: function (data) { return $.param(data); }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, responseType: 'arraybuffer' }).success(function (data) { var blob = new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); var da = new Date(); var fileName = "数据导出" + da.getFullYear() + '-' + (da.getMonth() + 1) + "-" + da.getDate(); self.saveas(blob, fileName); }); }; self.saveas = function (blob, fileName) { if (window.navigator.msSaveOrOpenBlob) { // For IE: navigator.msSaveBlob(blob, fileName+".xlsx"); } else { // For other browsers: var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = fileName + ".xlsx"; link.click(); window.URL.revokeObjectURL(link.href); } }
Related recommendations:
Nginx solves WebApi cross-domain secondary request example
Let WebAPI return data in JSON format tutorial
Share WebApi2 file and image upload and download function examples
The above is the detailed content of AngularJS uses webApi to export data. For more information, please follow other related articles on the PHP Chinese website!