function exportExcel(){
var m_url = '接口'
var xhr = new XMLHttpRequest();
xhr.responseType = "arraybuffer";
xhr.open("POST", m_url, true);
xhr.onload = function () {
const blob = new Blob([this.response], {type:"application/vnd.ms-excel"});
if(blob.size < 1) {
alert('导出失败,导出的内容为空!');
return;
}
var end = $("#endTime").val();
if(end==''){
var date = new Date();
end = date .getFullYear()+'-'+(date.getMonth()+1)+ '-'+date.getDate();
}
var fileName = '结案单汇总('+$("#beginTime").val()+'-'+end+').xls';
if(window.navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(blob, fileName)
} else {
const aLink = document.createElement('a');
aLink.style.display = 'none';
aLink.href = window.URL.createObjectURL(blob);
aLink.download = fileName;
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
return;
}
}
xhr.setRequestHeader("Authorization", "xxx");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send();
}
下载excel方法
最新推荐文章于 2024-04-17 20:24:51 发布