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)
????????????????????????????????????????//設(shè)置讀取的類
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .head(ExcelReadDemo.class)
????????????????????????????????????????//默認讀取第一個
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .sheet()
????????????????????????????????????????//設(shè)置標(biāo)題所在行
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .headRowNumber(1)
????????????????????????????????????????//異步讀取
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .doReadSync();