pom.xml
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.5</version>
</dependency>
3.0.5版本,不会因为poi的依赖报错java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/FileMagic
读取的xlsx样式
ExcelReadDemo类
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data //提供getset方法读取到list
public class ExcelReadDemo {
@ExcelProperty(value ="工号")
private Stringjob_number;
@ExcelProperty(value ="姓名")
private Stringjob_name;
@ExcelProperty(value ="总积分")
private Stringtotal_score;
@ExcelProperty(value ="健步积分")
private Stringstep_socre;
@ExcelProperty(value ="健身积分")
private Stringfit_socre;
@ExcelProperty(value ="阅读积分")
private Stringread_score;
@ExcelProperty(value ="志愿者积分")
private Stringvolunteer_score;
@ExcelProperty(value ="工间操积分")
private Stringwork_exercise_score;
}
读取代码>>>>>>
FileInputStream fileInputStream =null;
try {
//获取读取的文件
fileInputStream =new FileInputStream("C:\\Users\\1113\\Desktop\\查询信息表.xlsx");
}catch (FileNotFoundException e) {
throw new BusinessException(BusinessStatus.FAIL,"IO读取异常");
}
//读取
List list = EasyExcel.read(fileInputStream)
//设置读取的类
.head(ExcelReadDemo.class)
//默认读取第一个
.sheet()
//设置标题所在行
.headRowNumber(1)
//异步读取
.doReadSync();