EasyExcel简单使用

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")
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值