欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js使用blob导出excel,兼容IE

程序员文章站 2024-03-20 22:10:34
...
axios[method](url, data, {
   responseType: 'blob'  // blob arraybuffer
}).then(res => {
   let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'});
  
   if (!!window.ActiveXObject || "ActiveXObject" in window) {
        window.navigator.msSaveOrOpenBlob(blob, 'fileName');
   } else {
        const link = document.createElement('a');
        link.style.display = 'none';
        link.href = URL.createObjectURL(blob);
        link.setAttribute('download', 'fileName');
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
   }
   resolve(res);
}).catch(err => {
    reject(err);
})