EasyExcel简单使用
之前一直用的Apache POI来做数据的导入导出,但听说阿里的EasyExcel也拥有POI的功能的同时,在处理大数据量的导入导出的时候性能上比POI更好,所以就来尝试使用一下
导入Maven依赖:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.2.1</version> <!-- 请检查并使用最新稳定版本 -->
</dependency>
导出数据功能
导出模型类
定义一个导出数据模型类,用于设置excel文件的格式,通过注解的方式可以定义excel中的格式
@ColumnWidth(20) 设置excel中列的宽度为20;
@HeadStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER) 设置文本内容是否居中;
@HeadFontStyle(bold = BooleanEnum.FALSE) 设置字体是否加粗;
@ExcelProperty(value = “电话”, index = 0) 设置了excel中的标题,value则是标题内容,index则是内容所在的列的位置
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@ColumnWidth(20)
@HeadStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER)
@HeadFontStyle(bold = BooleanEnum.FALSE)
public class PmembersExportVO {
@ColumnWidth(15)
@ExcelProperty(value = "电话", index = 0)
private String mobile;
@ColumnWidth(15)
@ExcelProperty(value = "姓名", index = 1)
private String realname;
@ColumnWidth(10)
@ExcelProperty(value = "性别", index = 2)
private String gender;
@ColumnWidth(10)
@ExcelProperty(value = "省份", index = 3)
private String resideprovince;
@ColumnWidth(10)
@ExcelProperty(value = "城市", index = 4)
private String residecity;
@ColumnWidth(10)
@ExcelProperty(value = "区/县", index = 5)
private String residedist;
@ColumnWidth(20)
@ExcelProperty(value = "地址", index = 6)
private String address;
@ColumnWidth(12)
@ExcelProperty(value = "公历生日", index = 7)
private String birth;
@ColumnWidth(12)
@ExcelProperty(value = "农历生日", index = 8)
private String yinlibirth;
@ColumnWidth(12)
@ExcelProperty(value = "是否闰月", index = 9)
private String isLeapMonth;
}
controller代码
@ApiOperation("导出居士信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "weiqingview_backend_token", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "uniacid", value = "Unicid", required = true, dataType = "Integer", paramType = "query")
}


125

被折叠的 条评论
为什么被折叠?



