angular根据筛选的表格进行导出Excel表,或者全部导出表格。
1 $scope.outExcel = function () { 2 $http({ 3 method: 'GET', 4 url: '/device/all/download', 5 params: { //导出带的参数 6 'protocolVersion': $scope.protocolType, 7 'createTime': $scope.dateVal, 8 'deviceNum': $scope.pileNo, 9 'deviceStatus': $scope.deviceState 10 }, 11 headers:{ 12 'Content-type': undefined 13 }, 14 responseType: 'arraybuffer' 15 }).then(function successCallback(resp) { 16 var blob = new Blob([resp.data], {type: "application/vnd.ms-excel"});//type:"applicatuib/vnd.ms-excel" 导出的文件类型
18 var objectUrl = URL.createObjectURL(blob); 19 var a = document.createElement('a'); 20 document.body.appendChild(a); 21 a.setAttribute('style', 'display:none'); 22 a.setAttribute('href', objectUrl); 23 var filename = "devices.xls"; //文件扩展名 24 a.setAttribute('download',filename); 25 a.click(); 26 URL.revokeObjectURL(objectUrl); 27 }) 32 }