Excel文件在IE下導(dǎo)不出來(lái)

handleDownload(){
    let fileName='222';
    //fileName=encodeURIComponent(fileName);
    console.log(fileName);
    //導(dǎo)出
    if(this.ID){
      this.toDownload(this.uploadUrl,this.ID,fileName+'.xlsx')
    }else{
        this.$message.error('沒(méi)有數(shù)據(jù),無(wú)法導(dǎo)出!');
    }
},
toDownload(url, data, fileName) {
    return new Promise((resolve, reject) => {
        axios({
            method: "get",
            url: url,//請(qǐng)求后端接口url
            params:{ChlinicalID:data},
            responseType: 'blob'
        })
        .then(res => {
            let reader = new FileReader();
            let data = res.data;
            console.log(res);
            reader.onload = e => {
                if (e.target.result.indexOf('Result') != -1 && JSON.parse(e.target.result).Result == false) {
                    // 進(jìn)行錯(cuò)誤處理
                } else {
                    if (!fileName) {
                        let contentDisposition = res.headers['content-disposition'];
                        if (contentDisposition) {
                            fileName = window.decodeURI(res.headers['content-disposition'].split('=')[2].split("''")[1], "UTF-8");
                        }
                    }
                    this.executeDownload(data, fileName);
                }
            };
            reader.readAsText(data);
            resolve(res.data);
        })
    });
},
 //  模擬點(diǎn)擊a 標(biāo)簽進(jìn)行下載
executeDownload(data, fileName) {
  if (!data) {
         return
     }
     var blobData=new Blob([data]);
     if (navigator.msSaveOrOpenBlob) {//允許用戶在客戶端上保存文件,IE
         //IE瀏覽器
         navigator.msSaveOrOpenBlob(blobData,fileName);
     } else {
         //其他瀏覽器
         let url = window.URL.createObjectURL(blobData);
         console.log('url',url);
         let link = document.createElement('a');
         link.style.display = 'none';
         link.href = url;
         link.setAttribute('download', fileName);
         document.body.appendChild(link);
         link.click();//IE下不支持該方法
         document.body.removeChild(link);
     }
 },
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容