I am working on a requirement where i need to validate xlsx file records and display validations to end user.I am using Apache POI and The problem is when a row contains a date cell like(01/31/2015) during parsing it is going inside numeric cell type switch case and giving some unexpected value(42005 like that).
I cant use getDateCellValue since I am converting xls to csv and doing different validations there. Hence irrespective of xls formula/format, I should get the value exactly entered by the user for my requirement not only for date but for all other types ( as of now I found issue with only with date strings). I have tried below code and please update me with any other solutions since I am not sure that below code will work fine for all scenarios.
if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC){
if(DateUtil.isCellDateFormatted(cell)){
DataFormatter format= new DataFormatter();
FormulaEvaluator fe = Workbook.getCreationHelper().createFormulaEvaluator();
String str= format.formatCellValue(cell, fe);
return str;
}
}