Dates in Excel using POI

C

Chase Preuninger

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.
 
L

Lew

Chase said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top