POI export excel file front-end code

// Export query list
exportExcel () {
  crudArchivesManagement.exportExcel().then(res => {
    console.log(res)
    this.download(res)
  })
},
download(data) {
  if (!data) {
    return
  }
 // Create a new URL object, through this URL, you can get the complete content of the specified file
  const url = window.URL.createObjectURL(new Blob([data]))
 //document.createElement() is to create an object in the object
  let link = document.createElement('a')
  link.style.display = 'none'
  link.href = url
  link.setAttribute('download','effective customer file management.xlsx')
  document.body.appendChild(link)
  link.click()
  URL.revokeObjectURL(link.href) // release the URL object
  document.body.removeChild(link)
  link = null
},

 

js

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

Guess you like

Origin blog.csdn.net/weixin_45876619/article/details/107716031