Date vs. Numeric NPOI 2.0.6

Apr 24, 2014 at 5:06 PM
Does anyone know how to determine the difference between a cell being a date vs. a numeric value? I know dates are stored as numeric values in Microsoft Office. As a result, for all cells containing dates or numeric values the properties of the ICell object appear to have values for both NumericCellValue and DateCellValue. I could determine the proper format by looking at the NumberFormat property but I cannot find it attached to the cell object. Any ideas on how to make the distinction?

This poses a problem when reading in an Excel file because you would have to make the blind assumption if a cell was a date or numeric. There is no way to let the system choose the correct cell value to read.
Apr 29, 2014 at 4:22 PM
Edited Apr 29, 2014 at 5:16 PM
if (cell.CellType == CellType.Numeric)
{
 object[targetRowNum, targetColNum] = cell.NumericCellValue.ToString();
 if (DateUtil.IsCellDateFormatted(cell))
 {
     object[targetRowNum, targetColNum] = cell.DateCellValue.ToString("dd-MMM-yyyy");
 }
}

note: you need to use wb = WorkbookFactory.Create(filestream,ImportOption.All); ImportOption.All parameter allows DateUtil.IsCellDateFormatted to work properly in both reading excel 2007 and excel 2003.
Marked as answer by tonyqus on 5/12/2014 at 8:48 AM