Excel导出

59 阅读1分钟

image.png

image.png

/**
   api.YG_EXPORT:请求接口
   reallyCondition: 参数
   responseType: axios请求配置
*/
const exportData = async () => {
  const { data } = await request(api.YG_EXPORT, reallyCondition, {}, { responseType: 'blob' })
  const url = window.URL.createObjectURL(new Blob([data], {
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  }))
  const a = document.createElement('a')
  a.style.display = 'none'
  a.href = url
  a.setAttribute('download', 'excel.xlsx')
  document.body.appendChild(a)
  a.click()
  document.body.removeChild(a)
}