• 后端创文件流前端浏览器进行下载Excel(springboot+Vue)


    转载 https://blog.csdn.net/qq_34940644/article/details/99638156

        // 导出
        exportFun() {
          if (this.planListData.length === 0) {
            this.$message({
              message: "列表为空,无法导出",
              type: "error"
            });
            return;
          }
          this.isExport = false;
          this.exportList(this.searchData).then(res => {
              let blob = new Blob([res], {
                type:
                  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
              });
              let objectUrl = URL.createObjectURL(blob);
              let a = document.createElement("a");
              a.href = objectUrl;
              a.download = "补货计划报表";
              // a.click();
              //下面这个写法兼容火狐
              a.dispatchEvent(
                new MouseEvent("click", {
                  bubbles: true,
                  cancelable: true,
                  view: window
                })
              );
              window.URL.revokeObjectURL(blob);
          });
        },
        /**
        * @description 补货计划--列表-导出
        */
        async exportList({ dispatch }, params) {
            const res = await Axios.post(API.REPLENISH_PLAN_EXPORT.URL, params, { responseType: "blob" }).then(response => response)
                .catch(error => Promise.reject(error))
            return res;
        },
    async exportReport() {
          Axios.get("/sqdb/gwlog/v1/export", {
            params: {},
            responseType: "blob"
          }).then(res => {
            let blob = new Blob([res], {
              type:
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            });
            // console.log(blob);
            let objectUrl = URL.createObjectURL(blob);
    
            let a = document.createElement("a");
            a.href = objectUrl;
            a.download = "报表";
            // a.click();
            //下面这个写法兼容火狐
            a.dispatchEvent(
              new MouseEvent("click", {
                bubbles: true,
                cancelable: true,
                view: window
              })
            );
            window.URL.revokeObjectURL(blob);
          });
        },
  • 相关阅读:
    java 单例设计模式
    JAVAWEB监听器(二)
    pxe无人值守安装linux机器笔记----摘抄
    Ganglia3.1.7安装与配置(收录)
    Hadoop Sentry 学习
    安装和配置Sentry(收录)
    sqoop 的使用 -20160410
    深度分析如何在Hadoop中控制Map的数量(摘抄)
    CDH,CM下载
    大数据培训班 cloudera公司讲师面对面授课 CCDH CCAH CCP
  • 原文地址:https://www.cnblogs.com/MR-cui/p/12454913.html
Copyright © 2020-2023  润新知