Answer the question
In order to leave comments, you need to log in
How to parse an excel curve in java?
Hello!
I get an excel curve (the structure is not convenient for parsing), I need to write all the fields into an array of
excel objects:
my pojo:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RegisterModel {
private String date;
private String suip;
private String state;
private String transactionID;
}
public List<RegisterModel> parse(MultipartFile file) throws IOException {
Workbook workbook = new HSSFWorkbook(file.getInputStream());
Sheet worksheet = workbook.getSheetAt(0);
List<RegisterModel> registerModelList = new ArrayList<>();
for (int i = 3; i < 10; i++) {
Row row = worksheet.getRow(i);
RegisterModel registerModel = new RegisterModel();
String str = String.valueOf(row.getCell(1));
if (!str.contains("null")) {
// если дата
if (str.contains(":")){
registerModel.setDate(str);
}
// если число
if (NumberUtils.isDigits(str)){
registerModel.setTransactionID(str);
}
registerModelList.add(registerModel);
}
}
System.out.println(registerModelList);
return registerModelList;
}
[RegisterModel(date=2022-03-01T00:58:03, suip=null, state=null, transactionID=null), RegisterModel(date=null, suip=null, state=null, transactionID=502553852624)]
Answer the question
In order to leave comments, you need to log in
You need to parse both columns.
We parse the first - we understand what needs to be done with the second.
1. If the first one contains something like "oper_//d*" - create a new RegisterModel object, write the old one (if any) to registerModelList.
2. If something like OPERDAY - parse the second column, try to pull out the date (you can make several options for the date format, if necessary)
3. If SUITE, STATE, NUM_ORDER - similarly.
I would write some separate method that will parse the data from the first column and return commands from the enam.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question