You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Digo Chakraverty <ch...@hrs.de> on 2005/09/01 10:07:58 UTC

HSSFCell returns numeric value instaed of String

Hi all,

when I try to retrieve the values from some cells,
the returned format confuses me. Maybe you can help.

1. In Excel, I formatted all cells as Strings.
2. In the code it looks like this:

  private String convertToString(HSSFCell cell) {
         String ret = "";

         if (cell != null)
         {
             int type = cell.getCellType();
             switch (type)
             {
             case HSSFCell.CELL_TYPE_BLANK:
             case HSSFCell.CELL_TYPE_BOOLEAN:
             case HSSFCell.CELL_TYPE_ERROR:
             case HSSFCell.CELL_TYPE_FORMULA:
                 break;
             case HSSFCell.CELL_TYPE_NUMERIC:
                 ret = Double.toString(cell.getNumericCellValue());
                 System.out.println("number: " + ret);
                 break;
             case HSSFCell.CELL_TYPE_STRING:
                 ret = cell.getStringCellValue();
                 System.out.println("String: " + ret);
                 break;
             }
         }

         return ret;
     }


3. With Strings, erverything is ok. Values consisting of numbers
appear as numbers (although I had formatted them as Strings in Excel).
4.Furthermore,  A number like 736132469 is displayed as 7.36132469E8

Any suggestions?


Thank you very much.

Regards, Digo


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/


Re: HSSFCell returns numeric value instaed of String

Posted by do...@gmx.de.
Hi Digo,

my code is nearly like yours,


if (typ == HSSFCell.CELL_TYPE_NUMERIC) 		
     content.append(cell.getNumericCellValue()  + " ");

if (typ == HSSFCell.CELL_TYPE_STRING)      
     content.append(cell.getStringCellValue() + " "); 

and i try to reconstruct the situation you have!!

7.36132469E8 this form you get because the cell is formated in
this way! And HSSFCell take this in the format, how it is in the
exel file!

But i have a question about the cell numeration!!
I do the numeration that way:

for (int sheetNr = 0; sheetNr < workbook.getNumberOfSheets(); sheetNr++) {
for (int rowNr = sheet.getFirstRowNum(); rowNr <= sheet.getLastRowNum();
rowNr++) {

the Problem is that it miss out rows which first cell is empty!!!
Have anybody an idea?
Also i get an NullPointerException!!!

Bye Derya


> --- Ursprüngliche Nachricht ---
> Von: Digo Chakraverty <ch...@hrs.de>
> An: POI Users List <po...@jakarta.apache.org>
> Betreff: HSSFCell returns numeric value instaed of String
> Datum: Thu, 01 Sep 2005 10:07:58 +0200
> 
> Hi all,
> 
> when I try to retrieve the values from some cells,
> the returned format confuses me. Maybe you can help.
> 
> 1. In Excel, I formatted all cells as Strings.
> 2. In the code it looks like this:
> 
>   private String convertToString(HSSFCell cell) {
>          String ret = "";
> 
>          if (cell != null)
>          {
>              int type = cell.getCellType();
>              switch (type)
>              {
>              case HSSFCell.CELL_TYPE_BLANK:
>              case HSSFCell.CELL_TYPE_BOOLEAN:
>              case HSSFCell.CELL_TYPE_ERROR:
>              case HSSFCell.CELL_TYPE_FORMULA:
>                  break;
>              case HSSFCell.CELL_TYPE_NUMERIC:
>                  ret = Double.toString(cell.getNumericCellValue());
>                  System.out.println("number: " + ret);
>                  break;
>              case HSSFCell.CELL_TYPE_STRING:
>                  ret = cell.getStringCellValue();
>                  System.out.println("String: " + ret);
>                  break;
>              }
>          }
> 
>          return ret;
>      }
> 
> 
> 3. With Strings, erverything is ok. Values consisting of numbers
> appear as numbers (although I had formatted them as Strings in Excel).
> 4.Furthermore,  A number like 736132469 is displayed as 7.36132469E8
> 
> Any suggestions?
> 
> 
> Thank you very much.
> 
> Regards, Digo
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 

-- 
5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse für Mail, Message, More +++

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/