HSSF POI : How to know if data in cell is of Type Date?

Abhishek Singh picture Abhishek Singh · Aug 19, 2013 · Viewed 14.8k times · Source

Currently i have my code as

bean.setREPO_DATE(row.getCell(16).getDateCellValue());

it works fine if cell is formatted as date in excel.

However it also converts some integer or long like 1234 or 5699 to date. I know the reason behind this too.

However i want to apply a check before executing above line. Something like this

if(row.getCell(16).isOfDateFormat){
bean.setREPO_DATE(row.getCell(16).getDateCellValue());
} 

Please Guide me..

Thanks in Advance !

Answer

newuser picture newuser · Aug 19, 2013

Try this,

use import org.apache.poi.ss.usermodel.DateUtil;

if(DateUtil.isCellDateFormatted(cell))
   {
       cell.getDateCellValue();
   }