The front-end and back-end are separated. The front-end passes the post to the back-end through ng's $http, and the back-end returns data with response type application/vns.ms-excel. Is there any way to let the browser download the excel file?
// 創(chuàng)建a標(biāo)簽?zāi)M下載
function exportExcel(params, filename) {
return $http({
url: '/api/exportExcel',
method: "POST",
headers: {
'Content-type': 'application/json'
},
params: params,
responseType: 'arraybuffer'
}).success(function (data) {
var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
var objectUrl = URL.createObjectURL(blob);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display:none');
a.setAttribute('href', objectUrl);
a.setAttribute('download', filename);
a.click();
URL.revokeObjectURL(objectUrl);
});
}