前端代码excel导出,适配ie

   handleExport (data) {
      if (this.benchList.length === 0 || this.benchList === null) {
        this.$message.warning('不能导出空数据')
        return
      }
      let titlestr = ''
      let arr = []
      for (let i = 0; i < this.benchList.length; i++) {
        let obj = {}
        obj.index = i + 1
        obj.securityName = this.benchList[i].securityName
        obj.securityCode = this.benchList[i].securityCode
        arr.push(obj)
      }
      if (window.navigator.msSaveOrOpenBlob) {
        // 加上 \ufeff BOM 头,适配ie
        titlestr = '\ufeff'
      }
      this.$refs.scoreTable.columns.forEach((item) => {
        if (item.label === '序号' || item.label === '证券代码' || item.label === '证券名称') {
          titlestr += item.label + ','
        }
      })
      titlestr = titlestr.slice(0, titlestr.length - 1) + '\n'
      arr.forEach(item => {
        Object.keys(item).forEach(nitem => {
          titlestr += item[nitem] + ','
        })
        titlestr = titlestr.slice(0, titlestr.length - 1) + '\n'
      })
      if (window.navigator.msSaveOrOpenBlob) {
        // IE 浏览器  \n.使用后会发现列可以分开,但是不换行,使用decodeURIComponent 进行编码
        var blob = new window.Blob([decodeURIComponent(decodeURI(titlestr))], {
          type: 'data:text/csv;charset=utf-8,'
        })
        // Internet Explorer 10 的 msSaveBlob 和 msSaveOrOpenBlob 方法允许用户在客户端上保存文件
        navigator.msSaveBlob(blob, '成分股配股信息列表')
      } else {
        let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(titlestr)
        let link = document.createElement('a')
        link.href = uri
        link.download = '成分股配股信息列表'
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
      }
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值