本文主要和大家分享AngularJS使用webApi导出数据代码实例,希望本文的代码能帮助到大家。
/////导出功能 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); } }
登录后复制
相关推荐:
以上就是AngularJS使用webApi导出数据的详细内容,更多请关注Work网其它相关文章!