I want to get the date value from all the cells of a xlsx file using APACHE POI library.
Setting: The file contains strings,small integers like 12-15 (working hours) and dates in the dd/mm/yyyy format. I want to get all the dates from the current file.
switch (cell.getCellType()) {
case STRING:
break;
case NUMERIC:
return cell.getLocalDateTimeValue();
case BOOLEAN:
break;
default:
break;
}
Iterating through the cells and using the above code does not work because it converts the numeric 5 to 1/12/1900(not the exact numbers). Plus i don't want to hardcode something like:
if(date.isAfter(someDate)) {accept it }
The only solution i found was:
- Get the numeric value
- Convert it to string
- Use regex to match a specified format
- If it is accepted convert it back to date
I did not implement it yet. It seems like it is going to work but i think it's a bit messy.
Note:I am at junior level so i do not know if this is a good practice to convert it back and forth.
This answer throws me the error shown in the image as i iterate though cells