赞
踩
wu-easy-excel-starter是一款面向对象的excel、文件导出框架。
实现的功能:
1)针对Java中任何对象直接返回给web,在返回web过程自动将对象转换成想要的数据(Excel、File)
2)前端传一个Excel过来,后端接口接收到的其实已经是Bean了
依赖引入
<dependency>
<groupId>com.wu</groupId>
<artifactId>wu-easy-excel-starter</artifactId>
<version>1.2.3-JDK17</version>
</dependency>
@Data public class UseExcel { @EasyExcelFiled(name = "id") private Integer id; @EasyExcelFiled(name = "当前时间") private LocalDateTime currentTime; @EasyExcelFiled(name = "描述") private String desc; @EasyExcelFiled(name = "类型") private String type; } @EasyExcel(fileName = "导出数据") @GetMapping("/run/{size}") public List<UseExcel> run(@PathVariable Integer size) { List<UseExcel> useUserExcelList = new ArrayList<>(); for (int i = 0; i < size; i++) { UseExcel useExcel = new UseExcel(); useExcel.setCurrentTime(LocalDateTime.MAX); useExcel.setDesc("默认方式导出数据"); useExcel.setId(i); useExcel.setType("默认方式双注解导出"); useUserExcelList.add(useExcel); } return useUserExcelList; }
@Data public class UseExcel { @JSONField(name = "id") private Integer id; @JSONField(name = "当前时间") private LocalDateTime currentTime; @JSONField(name = "描述") private String desc; @JSONField(name = "类型") private String type; } @EasyExcel(fileName = "非原生注解导出数据", filedColumnAnnotation = JSONField.class,filedColumnAnnotationAttribute = "name",multipleSheet = true, limit = 10,sheetShowContext = EasyExcel.SheetShowContext.TEXT) @GetMapping("/run2/{size}") public List<UseExcel> run2(@PathVariable Integer size) { List<UseExcel> useUserExcelList = new ArrayList<>(); for (int i = 0; i < size; i++) { UseExcel useExcel = new UseExcel(); useExcel.setCurrentTime(LocalDateTime.MAX); useExcel.setDesc("自定义字段注解方式导出数据"); useExcel.setId(i); useExcel.setType("自定义字段注解导出"); useUserExcelList.add(useExcel); } return useUserExcelList; }
@Data
public class UseExcel {
@JSONField(name = "id")
private Integer id;
@JSONField(name = "当前时间")
private LocalDateTime currentTime;
@JSONField(name = "描述")
private String desc;
@JSONField(name = "类型")
private String type;
}
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@EasyExcel(useAnnotation = false,filedColumnAnnotation = JSONField.class)
public @interface EasyExcelTemp {
/**
* 文件名称
* @return String
*/
@AliasFor(annotation = EasyExcel.class,attribute = "fileName")
String fileName();
}
@EasyExcelTemp(fileName = "自定义注解导出")
@GetMapping("/run4/{size}")
public List<UseExcel> run4(@PathVariable Integer size) {
List<UseExcel> useUserExcelList = new ArrayList<>();
for (int i = 0; i < size; i++) {
UseExcel useExcel = new UseExcel();
useExcel.setCurrentTime(LocalDateTime.MAX);
useExcel.setDesc("自定义注解导出");
useExcel.setId(i);
useExcel.setType("自定义注解导出");
useUserExcelList.add(useExcel);
}
return useUserExcelList;
}
@Data @EasySmart(perfectTable = true) public class UseExcel { @EasyExcelFiled(name = "原生注解-id") @JSONField(name = "JSONField注解-id") private Integer excelId; @EasySmartField(name = "`current_time`") @EasyExcelFiled(name = "原生注解-当前时间") @JSONField(name = "JSONField注解-当前时间") private LocalDateTime currentTime; @EasySmartField(name = "`orderByDesc`") @EasyExcelFiled(name = "原生注解-描述",fieldMerge = EasyExcelFiled.EasyExcelFieldMerge.VERTICAL) @JSONField(name = "JSONField注解-描述") private String desc; @EasyExcelFiled(name = "原生注解-类型",fieldMerge = EasyExcelFiled.EasyExcelFieldMerge.VERTICAL) @JSONField(name = "JSONField注解-类型") private String type; @EasyExcelFiled(name = "原生注解-是否删除") @JSONField(name = "JSONField注解-是否删除") private boolean isDelete; }
新增注解 @EasyFile 支持导出字符串、文件到mvc框架二进制流文件
支持对象中含有对象
支持对象中含有集合导出自动合并集合
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。