// 下载模板
function DownloadExcel() {
console.log("进入方法");
const xhr = new XMLHttpRequest();
xhr.open("GET",url地址);
xhr.send();
xhr.responseType = 'blob'; //设置请求回来的数据为blob方式
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
// 数据在 this.response 保存
// excel 的 MIME 格式为 application/vnd.ms-excel
var blob = new Blob([this.response], {
type: "application/vnd.ms-excel"
});
// 创建a链接 href链接地址 download为下载下来后文件的名称
var aa = document.createElement('aaa');
aa.href = URL.createObjectURL(blob);
aa.innerHTML ='aaa';
aa.download ='aaa.xls';
aa.style.display = 'none'; //隐藏a标签 直接调用a标签的点击事件
document.body.appendChild(aa);
aa.click();
}
}
};
js调用后台接口下载excel文件
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java 如何再volatile内部调用接口
本文详细介绍了Java 如何在volatile内部调用接口的方法,并给出了两个详细的代码示例。
Java 发送消息 有序性 volatile内部调用接口 -
js循环调用接口
js循环调用接口 javascript循环调用接口 Buy me a cup of coffee :)
JavaScript html -
html5 js调用接口 js调用http接口
大家好,我是若川。持续组织了6个月源码共读活动,感兴趣的可以参与。大家好,我是 ConardLi ,今天给大家带来一个令人兴奋的好消息:Node.js 支持 Fetch API 啦! 在以前,使用原生的 Node.
html5 js调用接口 vue java js javascript