POI 导出excel 文件 前端代码

// 导出 查询列表
exportExcel() {
  crudArchivesManagement.exportExcel().then(res => {
    console.log(res)
    this.download(res)
  })
},
download(data) {
  if (!data) {
    return
  }
 // 创建一个新的URL对象,通过这个URL,可以获取到所指定文件的完整内容
  const url = window.URL.createObjectURL(new Blob([data]))
 //document.createElement()是在对象中创建一个对象
  let link = document.createElement('a')
  link.style.display = 'none'
  link.href = url
  link.setAttribute('download', '生效客户档案管理.xlsx')
  document.body.appendChild(link)
  link.click()
  URL.revokeObjectURL(link.href) // 释放URL 对象
  document.body.removeChild(link)
  link = null
},

js中

export function exportExcel() {
  return request({
    url: 'archives-management/exportQueryList',
    method: 'get',
    responseType: 'arraybuffer'
  })
}

猜你喜欢

转载自blog.csdn.net/weixin_45876619/article/details/107716031