上传excel时发现如果内容有多个回车 只会获取最后一段数据
** @Data public class ExcelDemoListeners extends AnalysisEventListener {
private List<Demo> demos = new ArrayList<>();
@Override
public void invoke(Object data, AnalysisContext context) {
Map<String,Object> map = (Map<String,Object>) data;
// Demo demo = new Demo(list.get(0), list.get(1)); // demos.add(demo); }
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
}**
@Slf4j
@Component
public class ExcelManager {
public String uploadExcel(MultipartFile file) throws IOException {
String filename = file.getOriginalFilename();
String suffix = filename.substring(filename.lastIndexOf("."), filename.length());
if (!(Objects.equals(suffix, ExcelTypeEnum.XLSX.getValue()) || Objects.equals(suffix, ExcelTypeEnum.XLS.getValue()))) {
log.info("传入得文件不是excel文件--{}", filename);
return null;
}
InputStream inputStream = file.getInputStream();
ExcelDemoListeners listeners = new ExcelDemoListeners();
EasyExcelFactory.read(inputStream, listeners).headRowNumber(1).sheet("Sheet1").doReadSync();
List<Demo> demos = listeners.getDemos();
return JSONObject.toJSONString(demos);
}
}
** excel 内容为:
MySQL安装请参考MySQL环境安装
笔者安装的时候的MySQL版本是8.0.15
库表的创建
最后解析出来得数据 "1" -> "笔者安装的时候的MySQL版本是8.0.15 库表的创建"
**