First some bad news; it is only possible to enter one of three different
types of value into a cell, a number, a String or a forumla which is itslef
a type of String I guess. Then you apply a format to that value to transform
the cells content into a Date value a currency value, etc. Therefore, it is
likely that POI is reporting the type of the cell correctly - it is a String
- that has then been formatted to look like a date.

The answer to your question depends a lot on what you actually want to do
with the value. If all you want to do is recover the contents of the cell as
a String and formatted as they appeared on the worksheet, then try using
DataFormatter -
http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DataFormatter.html
- which will return the contents of the cell to you as a correctly formatted
String. However, if you need the contents of the cell as a Date value, you
will first need to make sure that the cell does contain a date and there is
a class called DateUtil -
http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DateUtil.html - to
help, simply call the static isCellDateFormatted(Cell) method and pass
across the cell. This method will return true if the cell is formatted as a
date. Next, you will need to convert the String value the cell contains into
a Date object and this should be possible using the methods in the core Java
api - DateFormat.parse(String) for example - passing the cell's contents as
a String by calling either cell.GetRichStringCellValue().getString() or
getStringCellValue(). It may be worth making a second check after the
isCellDateFormatted() for cell type String. It could also be worth checking
to see whether you could use the DataFormatter class's methods to convert
the cells contents into a String and then simply pass this value to the Date
class constructor also.

Hope this helps a little.

Yours

Mark B


Kalpesh Modi-2 wrote:
> 
> Hi,
> 
>  
> 
> I have created an Excel template with few columns:
> 
>  
> 
> Name of the columns: User, First Name, Last Name, DOB
> 
>  
> 
> The DOB column is formatted as Date when creating the workbook template.
> 
>  
> 
> When I read the cell type for the DOB field, i.e. the actual column
> header DOB, it returns as String, even though its type is set to be
> Date.
> 
>  
> 
> Any ideas, how I can get the cell type as Date.
> 
>  
> 
> Thanks and regards,
> 
> -Kalpesh
> 
>  
> 
> 
> .
> The information contained in this e-mail message is intended only for the
> personal 
> and confidential use of the recipient(s) named above. This message is
> privileged 
> and confidential. If the reader of this message is not the intended
> recipient or an
> agent responsible for delivering it to the intended recipient, you are
> hereby notified 
> that you have received this document in error and that any review,
> dissemination, 
> distribution, or copying of this message is strictly prohibited.
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Getting-Data-type-tp29141500p29147093.html
Sent from the POI - User mailing list archive at Nabble.com.


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

Reply via email to