• 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
  • 相关阅读:
    二、跳转指定页面的JS代码
    一、常规的JS页面跳转代码
    您在前一家公司的离职原因是什么?
    如果你在这次面试中没有被录用,你怎么打算?
    如果你在这次面试中没有被录用,你怎么打算?
    针对你们单位业务工作中出现的问题,你提出了一些很好的建议,得到了同事们的赞同,但你的领导并不满意。在这种情况下,你怎么办?
    进程与线程的区别
    work13
    work12
    day09
  • 原文地址:https://www.cnblogs.com/shun1015/p/12558502.html
Copyright © 2020-2023  润新知