• vue下载文件(excel) 和 导出excel表格


    1. get形式传参数

    window.location = '/dms-underlying-asset/download?assetType=' + localStorage.getItem('assetType')
    

    2. post形式传参数

    this.download('http://10.7.160.108:8000/attendanceMonthResult/exportExcel', this.attenddateForm)
    
    download(url, params) {
          //console.log(url, params, '传过来的url和表单参数')
          // 创建form元素
          var temp_form = document.createElement('form')
          // 设置form属性
          temp_form.action = url
          temp_form.target = '_self'
          temp_form.method = 'post'
          temp_form.style.display = 'none'
          // 处理需要传递的参数
          for (var x in params) {
            var opt = document.createElement('textarea')
            opt.name = x
            opt.value = params[x]
            temp_form.appendChild(opt)
          }
          document.body.appendChild(temp_form)
          // 提交表单
          temp_form.submit()
        },


    // this.$refs['attenddateForm'].validate(valid => {
          //   if (valid) {
          //     let formdata = JSON.parse(JSON.stringify(this.attenddateForm))
          //     delete formdata.page //导出全部的数据,不需要传页码值
          //     delete formdata.size
          //     var temp_form = document.createElement('form')
          //     // 设置form属性
          //     temp_form.action = 'http://10.7.160.108:8000/attendanceMonthResult/exportExcel'
          //     temp_form.target = '_self'
          //     temp_form.method = 'post'
          //     temp_form.style.display = 'none'
          //     // 处理需要传递的参数
          //     for (var i in formdata) {
          //       var opt = document.createElement('textarea')
          //       opt.name = i
          //       opt.value = formdata[i]
          //       temp_form.appendChild(opt)
          //     }
          //     document.body.appendChild(temp_form)
          //     // 提交表单
          //     temp_form.submit()
          //   } else {
          //     this.$message.error('请输入必要的查询条件')
          //     return false
          //   }
          // })
     

    3,将表格的下载成excel表格(table表格绑定id)

    // 导出表格
          var wb = XLSX.utils.table_to_book(document.querySelector('#mytable')) //mytable为表格的id名
          var wbout = XLSX.write(wb, {
            bookType: 'xlsx',
            bookSST: true,
            type: 'array'
          })
          try {
            FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '考勤天数统计表.xlsx')
          } catch (e) {
            if (typeof console !== 'undefined') console.log(e, wbout)
          }
          return wbout
  • 相关阅读:
    [转]C#获取程序当前路径的方法
    [解决办法]未在本地计算机上注册“Mircosoft.Jet.OleDB.4.0”提供程序
    [解决办法]正在尝试使用已关闭或释放并且不再有效的 SPWeb 对象
    PowerShell学习笔记
    DNS
    在C#编程中,如何将Excel保存为2003的格式
    SAAS相关网络资源
    LCID及Culture Name列表
    Microsoft's naming conventions (微软命名规范)
    C#中如何结束Excel (Office)进程
  • 原文地址:https://www.cnblogs.com/shun1015/p/12558502.html
Copyright © 2020-2023  润新知