0

I was trying to read date form an excel using this code

case 2:
   if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { 
                        if ((cell.getDateCellValue()) != null) {

                            postAssumpContractPojo.setAssumptionDate(cell.getDateCellValue());

                        }
                    }
   Break;

But the first Condition is getting Flase ( if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC)) And in excel date is in this format (2014-10-14) Please Help ...

Anandv
  • 115
  • 1
  • 3
  • 10
  • Is there another `Cell` type which states whether the cell is a date? – James Fox Oct 30 '14 at 12:15
  • 1
    Make sure the cell in the excel sheet is actually of a date format and not just a text cell which includes a date like text. I suspect that is the case as a Date cell is a numeric type. – Jonathan Drapeau Oct 30 '14 at 12:18

1 Answers1

2

Check out the method in POI's DateUtil class for dealing with dates in Excelsheets, DateUtil.isCellDateFormatted()

You can get the date as shown below.

if (DateUtil.isCellDateFormatted(cell))
{
   try {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      cellValue = sdf.format(cell.getDateCellValue());

    } catch (ParseException e) {
            e.printStackTrace();
    }
}
Shishir Kumar
  • 7,981
  • 3
  • 29
  • 45