I am reading an excel file and am trying to find out which of the cell values are date values. Now, I tried doing it with getCellType of Apache POI SS User Model but the problem is my excel is returning String value even for the cells which contains Date value.
Is there a way to get around with this issue?
Below is my code for reference.
if (wb != null) {
sh = wb.getSheetAt(0);
CellStyle cellStyle = wb.createCellStyle();
CreationHelper createHelper = wb.getCreationHelper();
cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("DD-MM-YYYY HH:MM"));
System.out.println("Printing columns header.......");
for (int r = sh.getFirstRowNum()+1; r <= 10; r++) { //this for loop is iterating through all the rows of excel
Row currentRow = sh.getRow(r); //get r'th row
for (int c=currentRow.getFirstCellNum(); c<currentRow.getLastCellNum(); c++) { //this for loop is iterating through columns 4 to 7 of r'th row
Cell currentCell = currentRow.getCell(c); //get the c'th column
if (currentCell != null) {
CellType currentCellType = currentCell.getCellType();
if (currentCellType != null) {
System.out.print(currentCell.getCellType() + ":");
printCellValue(currentCellType, currentCell);
}
}
// if (DateUtil.isCellDateFormatted(currentCell)) {
// System.out.println("Current Cell value: " + currentCell.getDateCellValue());
// }
}
System.out.println();
}
}