日常开发中,难免遇到需要导入导出的业务场景,如果需要再表格的尾部插入一些自定义的统计项,传统的excel工具并不能提供很好的支持。
今天在这里给大家推荐一款非常好用的 Excel 导入导出工具工具: zouzhiy-excel 。可以实现自定义的表尾导出!
zouzhiy-excel 简介
zouzhiy-excel 是一款 Excel 导入导出的轻量级工具。对 POI 的接口做了一层封装,使导入导出更加简便快捷。
Spring 环境下集成
<dependency>
<groupId>io.github.zouzhiy</groupId>
<artifactId>zouzhiy-excel-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
开始使用
- 首先创建一对多的数据对象
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ExcelClass(rowFootWrite = CustomRowFootWrite.class)
public class FootVO {
@ExcelField(title = "姓名")
private String username;
@ExcelField(title = "年龄")
private Integer age;
@ExcelField(title = "分数")
private BigDecimal score;
}
rowFootWrite 指定自定义表尾写入的实现
- 实现我们自定义的表尾写入逻辑
@Component
public class CustomRowFootWrite implements RowFootWrite