You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by kiteflo <ki...@gmail.com> on 2011/04/19 10:11:58 UTC

Detect percentage value during parsing

Hi guys,

I am facing the following issue: I'm parsing through an excel, the excel
contains percentage fields such as 19%, 25%, 33,33% etc. as well as core
numeric fields (0.1234, 2.4567 ...).

We use the parse in order to generate an excel preview, therfore we have to
detect "somehow" whether a percentage cell or a default numeric cell has
been parsed, as POI (correctly) transforms percentage values to numeric ones
(19% -> 0,19 -> no clue whether this is a percentage field or numeric...)

Can anybody tell me how to recognize percentage values during parsing the
excel? I need sth like this...:

if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
{
   // percentage cell 
   if (cell.IS_PERCENTAGE_CELLTYPE....) 
   {
    ....
   }
   
   // default numeric cell...
   else
   {
   ...
   }
}

thanx in advance, Florian!

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Detect-percentage-value-during-parsing-tp4312746p4312746.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: Detect percentage value during parsing

Posted by kiteflo <ki...@gmail.com>.
thanx Nick, that's exactly what I was looking for...works like charm! 

Cheers, Flo!

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Detect-percentage-value-during-parsing-tp4312746p4314070.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: Detect percentage value during parsing

Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 19 Apr 2011, kiteflo wrote:
> Can anybody tell me how to recognize percentage values during parsing the
> excel? I need sth like this...:

You'll want to look at the DataFormat on the cell's style. Something like
    if("0%".equals( cell.getCellStyle().getDataFormatString() )) {
      // Percent
    }

Nick

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