Vue.js + SpringBoot 后台导出Excel表格
程序员文章站
2022-06-06 20:02:30
...
1、前端Vue.js
var data = this.$store.getters.excel.data;
let url = window.URL.createObjectURL(new Blob([data]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.download = 'XX.xlsx';
document.body.appendChild(link)
link.click()
window.URL.revokeObjectURL(link.href);
// 不能用拦截器
export function exportExcel(){
return axios({
url: process.env.BASE_API+'/api/export',
method: 'post',
headers: {"Authorization":+ getToken()},
responseType: 'blob',
data: {}
})
}
2、后端
Workbook book = ....
HttpServletResponse response
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-disposition", "attachment;fileName=XX.xlsx");
OutputStream out = response.getOutputStream();
out.flush();
book.write(out);
上一篇: vue导入导出Excel文件
下一篇: JS 导入导出 EXcel