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

时间:2020-03-24
本文章向大家介绍vue下载文件(excel) 和 导出excel表格,主要包括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()
    },

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

原文地址:https://www.cnblogs.com/shun1015/p/12558502.html