js excel下载
实现excel导出
// 导出代码写在一个公共方法中,引入到页面
import { exportExcel } from '@/utils/index'
// res是接口返回的文件流,第二个是文件名称,这里取的是列表文件名,要去掉后缀
exportExcel(res, row.fileName.replace(/\.xls(x)?/i, '')) // 导出Excel、zip压缩文件
export const exportExcel = (res, name, loadtype) => {let blob = nullif (loadtype !== '' && loadtype === 'zip') { // zipblob = new Blob([res], { type: 'application/zip' })const objectURL = URL.createObjectURL(blob)const downEle = document.createElement('a')downEle.href = objectURLdownEle.setAttribute('download', `${name}.zip`)document.body.appendChild(downEle)downEle.click()} else { // Excelblob = new Blob([res], { type: 'application/vnd.ms-excel' })const objectURL = URL.createObjectURL(blob)const downEle = document.createElement('a')downEle.href = objectURLdownEle.setAttribute('download', `${name}.xlsx`)document.body.appendChild(downEle)downEle.click()}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
