zoukankan      html  css  js  c++  java
  • 导出表格为excel文件

    不穿参全部导出

        UserExportDemo(){
          //注意传参方式
            console.log('导出人员档案为excel表格')
            let that = this;
            that.allLoading = true; //全局等待loading
            that.$axios1({
                method:'get',
                url:'/api/exportExcelUser', //接口
                responseType:'blob',
            })
            .then((res) => {
                console.log(res.data);
                that.allLoading = false;
                let blob = new Blob([res.data],{type: res.headers['content-type']});
                let downloadElement = document.createElement('a');
                let href = window.URL.createObjectURL(blob); //创建下载的链接
                downloadElement.href = href;
                downloadElement.download =  '人员档案'+'.xls'; //下载后文件名
                document.body.appendChild(downloadElement);
                downloadElement.click(); //点击下载
                document.body.removeChild(downloadElement); //下载完成移除元素
                window.URL.revokeObjectURL(href); //释放掉blob对象
            })
            .catch((err) => {
                console.log(err)
            });
        },
    

    传参导出部分

          //注意传参方式
            exportData(){
                let that = this;
                that.excelloading = true;
                let postData = {    
                    'batch.batchId':that.batchidArr,
                    'project.projectId':  that.projecridArr
                }
                console.log(postData,'导出传参')
                that.$axios1({
                    method:'post',
                    url:'GSPdwPC//ExcelReportAction!excelExportProjectInfo.action',
                    responseType:'blob',
                    data: postData , //将传递的参数变为字符形式
                })
                .then((res) => {
                    console.log(res.data);
                    that.excelloading = false;
                    let blob = new Blob([res.data],{type: res.headers['content-type']});
                    let downloadElement = document.createElement('a');
                    let href = window.URL.createObjectURL(blob); //创建下载的链接
                    downloadElement.href = href;
                    downloadElement.download = '工程基本信息表格.xls'; //下载后文件名
                    document.body.appendChild(downloadElement);
                    downloadElement.click(); //点击下载
                    document.body.removeChild(downloadElement); //下载完成移除元素
                    window.URL.revokeObjectURL(href); //释放掉blob对象
                })
                .catch((err) => {
                    console.log(err)
                });
            },
    

    加密方式导出

     const postData = {
             "type": this.fileprops.type
           }
          //先对传的参数进行加密
           let data1 = utils.encrypt(JSON.stringify(postData))
           this.$axios1({
             method: 'post',
             url:'GSPdwPC/CustomAction!download.action',
             data: that.qs.stringify({'data': data1}),  //传递给后台所需要的数据格式
             responseType: 'blob'
           }).then((response) => {
                  let blob = new Blob([res.data],{type: res.headers['content-type']});
                  let downloadElement = document.createElement('a');
                  let href = window.URL.createObjectURL(blob); //创建下载的链接
                  downloadElement.href = href;
                  downloadElement.download = '工程基本信息表格.xls'; //下载后文件名
                  document.body.appendChild(downloadElement);
                  downloadElement.click(); //点击下载
                  document.body.removeChild(downloadElement); //下载完成移除元素
                  window.URL.revokeObjectURL(href); //释放掉blob对象
           }).catch((err)=> {
             console.log(err)
           })
    

    模板导出

    方法一:

    可以同上面导出excel一样导出

    方法二:

    通过a标签进行导出
    <a href="直接写测试或者线上的接口地址"><el-button type="info">下载表格模板</el-button></a>

  • 相关阅读:
    爬取豆瓣电影
    post get 请求 headers注释哪些
    matlab 子图像subplot
    post请求get请求
    UA伪装
    urllib.request encode()/decode()
    urllib.parse quote/unquate/urlencode
    python 爬取图片
    二叉树满二叉树完全二叉树
    Linux | 性能分析系列学习 (1)
  • 原文地址:https://www.cnblogs.com/loveliang/p/13576073.html
Copyright © 2011-2022 走看看