下载excel

2021-12-27  本文已影响0人  卢卢2020

excel下载文件正确 下载报错

excel下载报错

// 下载二进制文件

customDownLoadZipGet(data, fileName) {

const blob = new Blob([data], { type: 'application/vnd.ms-excel' }) // 把得到的结果用流对象转一下

const a = document.createElement('a') // 创建一个<a></ a>标签

a.href = URL.createObjectURL(blob) // 将流文件写入a标签的href属性值

a.download = fileName // 设置文件名

a.style.display = 'none' // 藏起来a标签

document.body.appendChild(a) // 将a标签追加到文档对象中

a.click() // 模拟点击了a标签,会触发a标签的href的读取,浏览器就会自动下载了

a.remove() // 一次性的用完就删除a标签 },

//接口

Analysis(data)          .then((res) => {            this.customDownLoadZipGet(res, 'test.xlsm')          }) //调用方法 xlsm是后端返回的excel格式 

上一篇 下一篇

猜你喜欢

热点阅读