最近Vue项目中用到了导入导出功能,在网上搜索了一番之后,决定采用Blob方式,这也是大家推荐的一种的方式,特此做下记录。
导出Excel功能
这里不谈别人怎么实现的,我是从后台生成了Excel流文件返回给前端的。
下面具体看一下后台的代码:
/**
* 批量导出用户
* @param condition
* @param response
*/
@PostMapping("/exportUser")
public void exportUser(@RequestBody UserQueryCondition condition,HttpServletResponse response){
XSSFWorkbook book = new XSSFWorkbook();
try {
List list = indexService.exportUser(condition);
if (list != null && list.size() > 0) {
XSSFSheet sheet = book.createSheet("mySheent");
String[] vals = {"用户ID", "邮箱账号","昵称","年龄","性别","状态", "注册时间"};
createExcel(sheet, 0, vals);
f