>From previous post here is function that check for
date format:

//////////////////////////////////////////////////////////////////
        // 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 Androsov <[EMAIL PROTECTED]> wrote:

> 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:
> 
> {
> case HSSFCell.CELL_TYPE_STRING:
>       cl = cell.getStringCellValue();
> break;                                                        case
> HSSFCell.CELL_TYPE_NUMERIC:                           icl =
> cell.getNumericCellValue();
>       if (isCellDateFormatted(cell))                      
> {
>                                       // format in form of
> M/D/YY
>                                                           Calendar cal =
> Calendar.getInstance();
>                                                          
> cal.setTime(getJavaDate(icl,false));
>                                                           String pattern =
> getCellDateFormat(cell);
>                                                           SimpleDateFormat
> df = new SimpleDateFormat(pattern);
>                                                           String dateStr =
> df.format(cal.getTime());
>                                                   
>                       }
>                                                       else
> String dateStr =  Double.toString(icl));
>                                               break;
> --- Ilya Kasnacheev <[EMAIL PROTECTED]> wrote:
> 
> > I'm using POI HSSF, and I need to dump Excel file
> > into XML.
> > 
> > I've wrote most of it, but still have one problem
> > unresolved:
> > I'm looking for a way to get numeric cells'
> content
> > as a string, formatted 
> > exactly as they would be displayed by Excel
> itself.
> > I mean, date 38629 in "DD.MM.YYYY" should yield
> > "04.10.2005", and 2.25 in 
> > "# ?/?" should yield "2 1/4".
> > 
> > I haven't found a way to do that, and googling
> > redirects me into 
> > HSSFDataFormat which is unrelated, I fail to form
> a
> > relevant query.
> > 
> > Is there a way do get that string representation?
> Is
> > it already stored in 
> > Excel files with possibility to retrieve? Or maybe
> > there's a formatter 
> > somewhere which I've overlooked? A converter from
> > HSSF format to Java's 
> > NumberFormat and DateFormat (even if not
> universal)?
> > 
> > Maybe any third-party solutions? I guess this
> > problem should be pretty 
> > popular.
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > 
> > 
> 
> 
> 
>        
>
____________________________________________________________________________________
> Looking for a deal? Find great prices on flights and
> hotels with Yahoo! FareChase.
> http://farechase.yahoo.com/
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 



       
____________________________________________________________________________________
Yahoo! oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC

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

Reply via email to