As a simplistic solution, you could have a
Util class so that:
   Util.getAsStringValue(cell)
would switch on getCellType() and return the 
value as a string.

Personally I prefer a facade layer on top
of the usermodel classes to abstract such
behaviour that I use often in my code.

Also, consider the fact that depending on your
logic you may want to decide how to control
the toString behaviour eg. get the numeric value
formatted or not. My opinion is that the 
current api provides you more control rather
than impose a specific way of achieving these
goals.

Code duplication is can be easily solved by 
writing your own classes on top of POI.

HTH,
~ amol


> -----Original Message-----
> From: Sanjiv Jivan [mailto:[EMAIL PROTECTED]
> Sent: Friday, August 26, 2005 2:47 PM
> To: POI Users List
> Subject: Re: HSSFCell.getStringCellValue too strict
> 
> 
> Thanks Amol. I am using the getCellType() and a bunch of 
> if-then-else's to 
> extract the String representation of a cells value in a 
> utility method but 
> my point was that this was too much work just to extract the String 
> representation of the data. And that such a method should be 
> part of the 
> API. 
> 
> If you feel that HSSFCell.getStringCellValue() should return 
> only if the 
> data type is String else throw exception, them maybe it would 
> be nice if the 
> toString() method was overridden in this class.
> 
> Consider reading a spreadsheet and writing out an XML file 
> representation 
> where I just want to read the String values.
> 
> Thanks,
> Sanjiv
> 
> 
> 
> On 8/26/05, Amol Deshmukh <[EMAIL PROTECTED]> wrote:
> > 
> > Sanjiv,
> > you could switch on getCellType() and contruct the string 
> representation
> > yourself.
> > You may also want to consider using HSSFDataFormat class to 
> format the
> > string
> > as seen in excel.
> > 
> > ~ amol
> > 
> > > -----Original Message-----
> > > From: Sanjiv Jivan [mailto:[EMAIL PROTECTED]
> > > Sent: Friday, August 26, 2005 2:25 PM
> > > To: POI Users List
> > > Subject: HSSFCell.getStringCellValue too strict
> > >
> > >
> > > Hi,
> > > HSSFCell.getStringCellValue() thows various
> > > NumberFormatException's if the
> > > data type in Excel is not of String type. I think this is 
> too strict.
> > > Throwing an exception when getting a number from String field
> > > makes sense
> > > but I would much prefer if HSSFCell.getStringCellValue returned to
> > > toString() value of whatever the cell value.
> > >
> > > Thanks,
> > > Sanjiv
> > >
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > Mailing List: http://jakarta.apache.org/site/mail2.html#poi
> > The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
> > 
> >
> 

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

Reply via email to