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 Thu, 25 Mar 2004 15:23:12 GMT
Thanks for the response Matt. 

I have your code running now and I seem to almost be getting the generic XML
version of the processed spreadsheet that I wanted.

One thing I have noticed is that dates are only recognized as dates if the
cell is CUSTOM formatted (i.e. the dd-mm-yyyy type) and not if they are
specific DATE cell formats.

Is that something you noticed as well?

-DAB

> -----Original Message-----
> From: Matt Puccini [mailto:matt.puccini@acu-power.com] 
> Sent: Wednesday, March 24, 2004 6:11 PM
> To: POI Users List
> Subject: RE: Date Cell Recognition
> 
> 
> Sorry, that one is pretty important; here's the previous two 
> statements before the if:
> 
>     case HSSFCell.CELL_TYPE_NUMERIC :
>         double d = cell.getNumericCellValue();
> 
> For your other question:
> ...should those clauses actually be ANDed or ORed? i.e. do
> all the terms have to be true for a cell to be a date, or 
> just one of them...
> 
> I'm not sure, to tell you the truth.  I know I needed all 
> three conditions to determine a valid date - I had many 
> values return true for the first two conditions though they 
> weren't really dates.
> 
> -matt
> 
> 
> -----Original Message-----
> From: Bigwood, David [mailto:dbigwood@metatomix.com]
> Sent: Wednesday, March 24, 2004 3:55 PM
> To: POI Users List
> Subject: RE: Date Cell Recognition
> 
> 
> 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
> 
> 
> ---------------------------------------------------------------------
> 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