• 使用文件流 导出 excel表


    大多数excel表格的导出,直接一个a标签跳转就行了

    但是为了安全考虑,有些公司前端需要用post方式获取后端返回的文件流,前端使用node将文件流转译后再导出

    下面就是代码

    exportBtn(){
      //导出修改为读取二进制文件流
          let parm = {
            report_type: this.sheetType,
            set_id: this.searchName,
            selectDate: selectDate,
            startTime: startTime,
            endTime: endTime,
          };
          api_tws.excelReport(qs.stringify(parm)).then((res) => {
            if (res == "apiError") {
              this.buttonDisabledType = false;
              return;
            }
            const blob = new Blob([res]);
            const elink = document.createElement("a");
    
            elink.download = `报表.xls`;
            elink.style.display = "none";
            elink.href = URL.createObjectURL(blob);
    
            document.body.appendChild(elink);
            elink.click();
            URL.revokeObjectURL(elink.href); // 释放URL 对象
            document.body.removeChild(elink);
            this.buttonDisabledType = false;
          });  
    }
    
    
    //上面是方法,下面是定义的api请求
    
    
    export async function excelReport(body) {
      const res = await axios({
        method: "post",
        responseType: "blob",
        url: serverUrl + '/excelReport/export?' + body
      });
      return res;
    }
    

      

  • 相关阅读:
    linux内存管理之数据结构必备
    Script快速入门与查表
    Bash编程linux诸多熟记命令
    NandFlash/NorFlash源码模型和驱动编写方法
    linux内存管理之uboot第一步
    《Magus Night》
    《P2447 [SDOI2010]外星千足虫》
    DFS 树的理解
    《2021CCPC桂林》
    《GRAPH》
  • 原文地址:https://www.cnblogs.com/wangqi2019/p/14073980.html
Copyright © 2020-2023  润新知