Closed qzyReal closed 5 years ago
public void importExcel(MultipartFile file, Long schoolId) throws Exception { try (InputStream is=file.getInputStream()){ ExcelReader excelReader = EasyExcel.read(is, TimetableVo.class, excelDataListener).build(); int total = excelReader.excelExecutor().sheetList().size(); for (int sheetNo = 0; sheetNo < total; sheetNo++) { ReadSheet readSheet = EasyExcel.readSheet(sheetNo).build(); excelReader.read(readSheet); } excelReader.finish(); } } ---监听器--- @Slf4j @Component public class ExcelDataListener extends AnalysisEventListener {
@Override public void invoke(TimetableVo data, AnalysisContext context) { log.info("数据:{}", data); } @Override public void doAfterAllAnalysed(AnalysisContext context) { log.info("解析完成!"); }
} ----modal---- @Data public class TimetableVo { @ExcelProperty(index = 0) private String stay;
@ExcelProperty(index = 1) private String period; @ExcelProperty(index = 2) private String time; @ExcelProperty(index = 3) private String monday; @ExcelProperty(index = 4) private String Tuesday; @ExcelProperty(index = 5) private String Wednesday; @ExcelProperty(index = 6) private String Thursday; @ExcelProperty(index = 7) private String Friday; @ExcelProperty(index = 8) private String Saturday; @ExcelProperty(index = 9) private String sunday;
}
请尝试下 2.0.2 这个应该是 获取sheetList 03版本有问题
public void importExcel(MultipartFile file, Long schoolId) throws Exception { try (InputStream is=file.getInputStream()){ ExcelReader excelReader = EasyExcel.read(is, TimetableVo.class, excelDataListener).build(); int total = excelReader.excelExecutor().sheetList().size(); for (int sheetNo = 0; sheetNo < total; sheetNo++) { ReadSheet readSheet = EasyExcel.readSheet(sheetNo).build(); excelReader.read(readSheet); } excelReader.finish(); } } ---监听器--- @Slf4j @Component public class ExcelDataListener extends AnalysisEventListener {
} ----modal---- @Data public class TimetableVo { @ExcelProperty(index = 0) private String stay;
}