There is not a real date cell type.  Its just a number that is formatted 
to be a date.  To experiment with this set it to general data type. 
 Then it will just be a straight number.

Hoffman, Jason wrote:

>Oliver, 
>
>I also have the same question.  This is the way I've implemented, which
>obviously has alot of room for error.  
>
>
>case HSSFCell.CELL_TYPE_NUMERIC:
>                  double d = cell.getNumericCellValue();
>                  // test if a date!
>// TODO -- this cant be more error prone!  But, the POI library currently
>//         does not have a CELL_TYPE_DATE !
>                  if ( HSSFDateUtil.isValidExcelDate(d)) {
>                    // Okay, lets put a sanity check in here.  18615 = 1951
>                    // anything earlier than 1990 is NOT A DATE ( for My app
>anyway )
>                    if (d > 18615.0) {
>                      // format in form of M/D/YY
>                      cal.setTime(HSSFDateUtil.getJavaDate(d));
>                      cellText =
> 
>(String.valueOf(cal.get(Calendar.YEAR))).substring(2);
>                      cellText = cal.get(Calendar.MONTH)+1 + "/" +
>                                 cal.get(Calendar.DAY_OF_MONTH) + "/" +
>                                 cellText;
>                    } else {
>                      // Do some special formating if a number
>                      if ( d >= 0 ) {
>                        long l = (long)d;
>                        double ld = l;
>                        if ( ld == d )
>                          cellText = String.valueOf(l);
>                        else
>                          cellText = String.valueOf(d);
>                      } else {
>                        cellText = String.valueOf(d).substring(1);
>                      }
>                    }
>                  } else {
>                    cellText = String.valueOf(d);
>                  }
>                  //cellText = String.valueOf(cell.getNumericCellValue());
>                break;
>
>-----Original Message-----
>From: Oliver Fuerniss [mailto:[EMAIL PROTECTED]]
>Sent: Thursday, April 18, 2002 8:26 AM
>To: [EMAIL PROTECTED]
>Subject: How to find out if a cell contains a Date
>
>
>Hello,
>i am using the poi dev version 1.5.0 and i have the following questions:
>Is there an way to find out, if the current cell contains a date? The method
>
>getCellType() delivers always CELL_TYPE_NUMERIC for my dates. Why is there
>no 
>constant for cell.getCellType() like HSSFCell.CELL_TYPE_DATETIME? 
>Also cell.getCellStyle().getDataFormat() is always 0 (General). 
>Thanx 
>  Oliver
>



Reply via email to