wu-easy-excel-starte是一个简单的Excel数据封装框架,具有以下优势
框架默认使用poi-ooxml版本可有外层控制
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-easy-excel-starter</artifactId>
<version>1.0.4</version>
</dependency>
@EasyExcel(fileName = "导出数据")
@ApiOperation(tags = "导出注解测试", value = "使用原生注解有效")
@GetMapping("/run/{size}")
public List<UseExcel> run(@PathVariable Integer size) {
List<UseExcel> useExcelList = new ArrayList<>();
for (int i = 0; i < size; i++) {
UseExcel useExcel = new UseExcel();
useExcel.setCurrentTime(LocalDateTime.now());
useExcel.setDesc("默认方式导出数据");
useExcel.setExcelId(i);
useExcel.setType("默认方式双注解导出");
useExcelList.add(useExcel);
}
return useExcelList;
}
@EasyExcel(fileName = "导出数据多个工作簿", multipleSheet = true)
@ApiOperation(tags = "导出注解测试", value = "使用原生注解有效多个工作簿")
@GetMapping("/run1/{size}")
public List<UseExcel> run1(@PathVariable Integer size) {
return run(size);
}
@EasyExcel(fileName = "非原生注解导出数据", fieldColumnAnnotation = JSONField.class, fieldColumnAnnotationAttribute = "tableName", multipleSheet = true, limit = 1000, sheetShowContext = EasyExcel.SheetShowContext.TEXT)
@ApiOperation(tags = "导出注解测试", value = "非原生注解导出数据")
@GetMapping("/run2/{size}")
public List<UseExcel> run2(@PathVariable Integer size) {
List<UseExcel> useExcelList = new ArrayList<>();
for (int i = 0; i < size; i++) {
UseExcel useExcel = new UseExcel();
useExcel.setCurrentTime(LocalDateTime.now());
useExcel.setDesc("自定义字段注解方式导出数据");
useExcel.setExcelId(i);
useExcel.setType("自定义字段注解导出");
useExcelList.add(useExcel);
}
return useExcelList;
}
@EasyExcel(fileName = "导出所有字段", useAnnotation = false)
@ApiOperation(tags = "导出注解测试", value = "导出所有字段")
@GetMapping("/run3/{size}")
public List<UseExcel> run3(@PathVariable Integer size) {
List<UseExcel> useExcelList = new ArrayList<>();
for (int i = 0; i < size; i++) {
UseExcel useExcel = new UseExcel();
useExcel.setCurrentTime(LocalDateTime.now());
useExcel.setDesc("不使用注解导出所有字段");
useExcel.setExcelId(i);
useExcel.setType("导出所有字段");
useExcelList.add(useExcel);
}
return useExcelList;
}
@EasyExcelTemp(fileName = "自定义注解导出")
@ApiOperation(tags = "导出注解测试", value = "自定义注解导出")
@GetMapping("/run4/{size}")
public List<UseExcel> run4(@PathVariable Integer size) {
List<UseExcel> useExcelList = new ArrayList<>();
for (int i = 0; i < size; i++) {
UseExcel useExcel = new UseExcel();
useExcel.setCurrentTime(LocalDateTime.now());
useExcel.setDesc("自定义注解导出");
useExcel.setExcelId(i);
useExcel.setType("自定义注解导出");
useExcelList.add(useExcel);
}
return useExcelList;
}
@EasyExcel(fileName = "导出数据")
@ApiOperation(tags = "导出注解测试", value = "使用原生注解有效(自定义一导出文件名称)")
@GetMapping("/run6/{size}")
public List<UseExcel> run6(@PathVariable Integer size, @RequestParam String fileName) {
EasyExcelUtil.modifyCurrentMethodEasyExcelFileName(this.getClass(), fileName);
return run(size);
}
@ApiOperation(tags = "导入注解测试", value = "导入Excel并转换成对象")
@PostMapping("/imp1")
public String import1(@RequestPart MultipartFile multipartFile) {
List<UseExcel> userLogList = FastExcelImp.parseExcel(multipartFile, UseExcel.class);
return userLogList.toString();
}
@ApiOperation(tags = "导入注解测试", value = "导入Excel并转换成EasyHashMap对象")
@PostMapping("/imp1/hash-map")
public List<EasyHashMap> implMap(@RequestPart MultipartFile file) {
List<EasyHashMap> easyHashMapList = FastExcelImp.parseExcel(file, EasyHashMap.class);
if (ObjectUtils.isEmpty(easyHashMapList)) {
return easyHashMapList;
}
return easyHashMapList;
}