前言:
Excel 导入是一个非常常见的功能,项目开发中随处可见,市面上也有各种处理 Excel 的 API,本文简单分享一下 alibaba.excel 的导入功能。
引入依赖:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.2.1</version>
</dependency>
定义实体类:
@Data
public class ImportVO {
@ExcelProperty(index = 0, value = {
"手机号"})
private String phoneNo;
@ExcelProperty(index = 1, value = {
"用户姓名"})
private String userName;
@ApiModelProperty("分值")
@ExcelProperty(index = 1, value = {
"分值"})
private BigDecimal score;
@ApiModelProperty("部门")
@ExcelProperty(index = 3, value = {
"部门"})
private String department;
}
创建监听器:
需要注意的是监听器不能被 Spring 管理,每次使用时需要 new 来创建对象,需要用到 Spring 对象的时候,可以通过构造方法传进去,或者使用 getBean 方法来获取。
@Data
@EqualsAndHashCode(callSuper =</