I am trying to parse an excel sheet which have date in its cell.But when my code is parsing it is converting the date to a double i.e 42921,43098 , i have to parse back that double to a date so that i can get the proper output.Also i have to maintain the code compatible to java 6 only.I am using poi 3.6.So what i have tried is below ,
private String formatDoubleNumberToString(double number) {
String formattedNumber = NumberToTextConverter.toText(number);
// replace E notation format
if (formattedNumber.contains("E")) {
formattedNumber = String.format("%." + DECIMAL_PLACES + "f", number);
formattedNumber = formattedNumber.indexOf(DECIMAL_SEPARATOR) < 0 ? formattedNumber
: formattedNumber.replaceAll("0*$", "").replaceAll("\\" + DECIMAL_SEPARATOR + "$", "");
}
else if(DateUtil.isValidExcelDate(double number)){ //here i am trying to check the double is of type Date
// convert the date using simpleDateFormat
}
return formattedNumber;
}
I am trying to check the number is of type date using isValidExcelDate(double value) , but it is also considering other double value as date and this cheking is not working .Can anyone have any idea about this ? Please help.