alibaba / easyexcel

快速、简洁、解决大文件内存溢出的java处理Excel工具
https://easyexcel.opensource.alibaba.com
Apache License 2.0
32.35k stars 7.52k forks source link

使用2.0.0版本读取excel的时候会发现模型中index>3的列数据无法读取 #617

Closed qzyReal closed 5 years ago

qzyReal commented 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;

}

zhuangjiaju commented 5 years ago

请尝试下 2.0.2 这个应该是 获取sheetList 03版本有问题