parse csv、excel files
-
Use Apache POI and easyexcel to analyze Excel files
-
Support parsing CSV files
-
Support parsing large excel
<dependency>
<groupId>com.github.shootercheng</groupId>
<artifactId>common-parse</artifactId>
<version>1.3</version>
</dependency>
Use code to create excel column to model field mapping, or use annotation form
Map<String, String> fieldColumnMap = new HashMap<>(16);
fieldColumnMap.put("A", "name");
fieldColumnMap.put("B", "gender");
fieldColumnMap.put("C", "num");
Map<String, Method> columnMethodMap = FileParseCommonUtil.convertToColumnMethodMap(UserInfo.class, fieldColumnMap);
ParseParam parseParam = new ParseParam().setStartLine(1)
.setFieldSetterMap(columnMethodMap);
default sheet is 0
@Location(column = "A")
private String name;
@Location(column = "B")
private String gender;
@Location(column = "C")
private String num;
If you need to parse multiple sheet pages
@Location(column = "A")
private String string;
@Location(column = "B")
private String date;
@Location(column = "C")
private Double doubleData;
@Location(column = "D")
private Date utDate;
@Location(sheet = 1, column = "A")
private Integer id;
@Location(sheet = 1, column = "B")
private String userName;
@Location(sheet = 1, column = "C")
private Double score;
@Location(sheet = 1, column = "D")
private Date rdate;
Three types of parsers are supported
- CsvFileParse
- EasyExcelParse
- ExcelFileParse
Different parsers are selected according to the parameters of different file types. If you have a parser of the same file type, you can specify
FileParse fileParse = FileParseCreateor.createFileParse(FileParseCommonUtil.findParserType(filePath, parseParam));
Specify a parser
parseParam.setParseType(ParseType.EASYEXCEL);
FileParse fileParse = FileParseCreateor.createFileParse(FileParseCommonUtil.findParserType(filePath, parseParam));
List<ReflectVo> reflectVoList = fileParse.parseFile(filePath, ReflectVo.class, parseParam);