poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bigwood, David" <dbigw...@metatomix.com>
Subject RE: Date Cell Recognition
Date Wed, 24 Mar 2004 22:54:33 GMT
Oh and one more thing where does the variable d come from in:

HSSFDateUtil.isValidExcelDate(d) && 



> -----Original Message-----
> From: Matt Puccini [mailto:matt.puccini@acu-power.com] 
> Sent: Wednesday, March 24, 2004 5:47 PM
> To: POI Users List
> Subject: RE: Date Cell Recognition
> 
> 
> David,
> 
> I had some trouble with that too.  I am using the usermodel, 
> and my solution may be a bit clunky, but it worked for me. Here it is:
> 
>     HSSFCell cell  = row.getCell((short)c);
>     //...
>         if (HSSFDateUtil.isCellDateFormatted(cell) && 
>             HSSFDateUtil.isValidExcelDate(d) && 
>             isDateFormat(cell)) {
>                 //...
>             }
>     //...
> 
>     /**
>      * Tests to see if a cell format is recognized as a date format.
>      * Strangely, the HSSFCellStyle.getDataFormat() function will
>      * sometimes return values that aren't valid indexes in the
>      * HSSFDataFormat.getBuiltinFormat() function - thus the catch
>      * ArrayIndexOutOfBoundsException.  I had some dates return an 
>      * index of 164, which I hard-coded into the catch clause.  Make 
>      * sure it doesn't miss other valid date formats because of this.
>      */
> 
>     private boolean isDateFormat(HSSFCell hCell) {
>       try {
>           String formatString = 
>               
> HSSFDataFormat.getBuiltinFormat(hCell.getCellStyle().getDataFormat());
>           if(formatString.equals("m/d/yy")  ||
>             formatString.equals("d-mmm-yy") ||
>             formatString.equals("d-mmm")    ||
>             formatString.equals("mmm-yy")   ||
>             formatString.equals("m/d/yy h:mm")) {
>               return true;
>           }
>       }
>       catch (ArrayIndexOutOfBoundsException ex) {
>           /* a bit of hard code - I don't know why, but sometimes
>            * valid dates are returning with an index of 164...
>            * Anyone knows why please let me know.
>            */
>           if(hCell.getCellStyle().getDataFormat() == 164) {
>               return true;
>           }
>           return false;
>       }
>       return false;
>     }
> 
> -----Original Message-----
> From: Bigwood, David [mailto:dbigwood@metatomix.com]
> Sent: Wednesday, March 24, 2004 3:30 PM
> To: POI Users List
> Subject: Date Cell Recognition
> 
> 
> Has anybody successfully managed to recognize a date cell and 
> differentiate
> it from a numeric cell for either:
> 
> 1. eventmodel
> 2. usermodel
> 
> And would they care to contribute a code snippet. I cannot 
> figure out how to
> do it reliably with the eventmodel and the method used in the 
> usermodel (see
> below) always returns false even even when cell is date formatted.
> 
> boolean isDate = HSSFDateUtil.isCellDateFormatted(cell);
> 
> Any insight you may have would be great.
> 
> -DAB
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org


Mime
View raw message