Here are 3 methods you may need to impliment date
conversion. These are not my functions but part of one
of POI examples I got it long ago from one of POI
forums or sample cases. Do not recall where but here
it is:

              /**
               * Given a double, checks if it is a valid
Excel date.
               *
               * @return true if valid
               * @param  value the double value
               */
              public static boolean isValidExcelDate(double
value)
              {
                  return (value > -Double.MIN_VALUE);
              }
        
         
///////////////////////////////////////////////////////////////
          // Method returns Java date pattern mapped from
Excel date
          public static String getCellDateFormat(HSSFCell
cell)
          {
                  String dt = "dd-MMM-yy";
              HSSFCellStyle style = cell.getCellStyle();
              int i = style.getDataFormat();
              switch(i) 
              {
            // Internal Date Formats as described on page 427
in Microsoft Excel Dev's Kit...
                case 0x0e: //m/d/yyyy
                        dt = "MM/dd/yyyy";
                        break;
                case 0x0f: //d-mmm
                        dt = "dd-MMM";
                        break;
                case 0x10: //d-mmm-yy
                        dt = "dd-MMM-yy";
                        break;
                case 0x11: //mmm-yy
                        dt = "MMMM-yy";
                        break;
                case 0x12: //h:mmAM/PM
                        dt = "hh:mm aa";
                        break;          
                case 0x13: //h:mm:ssAM/PM
                        dt = "hh:mm:ss aa";
                        break;
                case 0x14: //h:mm
                        dt = "hh:mm";
                        break;
                case 0x15: //h:mm:ss
                        dt = "hh:mm:ss";
                        break;
                case 0x16: //m/d/yyyy h:mm
                        dt = "MM/dd/yyyy hh:mm";
                        break;
                case 0x2d: //mm:ss
                        dt = "mm:ss";
                        break;
                case 0x2e: //[h]:mm:ss
                        dt = "hh:mm:ss";
                        break;
                case 0x2f: //mm:ss.0
                    dt = "mm:ss.SSSS";
                break;
                
                default:
                        dt = "dd-MMM-yy";
                break;
              }  
                  
                  return dt;
          }
        

//////////////////////////////////////////////////////////////////
        // method to determine if the cell is a date, versus
a number...
        public static boolean isCellDateFormatted(HSSFCell
cell) 
        {
            boolean bDate = false;
        
            double d = cell.getNumericCellValue();
            if ( isValidExcelDate(d) ) {
              HSSFCellStyle style = cell.getCellStyle();
              int i = style.getDataFormat();
              switch(i) {
            // Internal Date Formats as described on page 427
in Microsoft Excel Dev's Kit...
                case 0x0e:
                case 0x0f:
                case 0x10:
                case 0x11:
                case 0x12:
                case 0x13:
                case 0x14:
                case 0x15:
                case 0x16:
                case 0x2d:
                case 0x2e:
                case 0x2f:
                 bDate = true;
                break;
        
                default:
                 bDate = false;
                break;
              }
            }
            return bDate;
          }

Igor
--- Ilya Kasnacheev <[EMAIL PROTECTED]> wrote:

> ÷ ÓÏÏÂÝÅÎÉÉ ÏÔ 14 éÀÌØ 2007 05:49 Igor Androsov
> ÎÁÐÉÓÁÌ(a):
> > You can use HSSFCel object to get the data type,
> if
> > its string string you done. If its other types
> numeric
> > it may be date number etc you can formatit.
> > I used this code to deal with dates numerics: 
> Thanx! I have similar code in place, but still have
> some mysteries:
> 
> > {
> > case HSSFCell.CELL_TYPE_STRING:
> >  cl = cell.getStringCellValue();
> > break;                           case
> > HSSFCell.CELL_TYPE_NUMERIC:                  icl =
> > cell.getNumericCellValue();
> >  if (isCellDateFormatted(cell))                   
>   {
> I've tried this function, it failed to recongise
> date formats from my 
> ooo-saved excel document with 
> 
> So I've falled to home-grown 
>  private static boolean isDateFormat(HSSFCell cell,
> HSSFDataFormat format)
>  {
>   short fmt = cell.getCellStyle().getDataFormat();
>   String df = format.getFormat(fmt);
>   if(df.indexOf('D') >= 0
>    || df.indexOf('M') >= 0
>    || df.indexOf('Y') >= 0
>    || df.indexOf('H') >= 0
>    || df.indexOf('S') >= 0)
>    return true;
>   return false;
>  }
> 
> It kinda works, but I guess I might have missed
> something.
> 
> >                               // format in form of
> > M/D/YY
> >                                     Calendar cal =
> > Calendar.getInstance();
> >
> > cal.setTime(getJavaDate(icl,false));
> >                                     String pattern
> =
> > getCellDateFormat(cell);
> I can't find this function in library, and syntax
> suggests it's your locally 
> defined method.
> 
> Can you please send its contents to me or to this
> list, I guess it's really 
> what I'm looking for.
> 
> Anyway, thanx for support!
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 



 
____________________________________________________________________________________
We won't tell. Get more on shows you hate to love 
(and love to hate): Yahoo! TV's Guilty Pleasures list.
http://tv.yahoo.com/collections/265 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to