From: Chase Preuninger on
I need to extract dates from an excel file and convert them to
strings. The only catch is that they must be formatted the EXACT same
way they were in the excel file. How can I do this. I know you can
get the data format string but I don't know how to use it.
From: Lew on
Chase Preuninger wrote:
> I need to extract dates from an excel [sic] file [using POI] and convert them to
> strings.  The only catch is that they must be formatted the EXACT same
> way they were in the excel [sic] file.  How can I do this.  I know you can
> get the data format string but I don't know how to use it.
>

Looks like you need to get the CellStyle of the cell
<http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/
CellStyle.html>
and invoke
<http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/
HSSFCellStyle.html#getDataFormat()>
or
<http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/
HSSFCellStyle.html#getDataFormatString()>
on it. You should be able to use the BuiltinFormats value
<http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/
BuiltinFormats.html>
to build a DateFormat
<http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html>
that will do what you want.

I'm just learning POI myself.

--
Lew