Dates in Excel using POI

Discussion in 'Java' started by Chase Preuninger, Jun 28, 2010.

  1. 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.
     
    Chase Preuninger, Jun 28, 2010
    #1
    1. Advertising

  2. Chase Preuninger

    Lew Guest

    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
     
    Lew, Jun 28, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    904
    Rob Schieber
    Sep 30, 2005
  2. davisoski
    Replies:
    0
    Views:
    1,542
    davisoski
    Aug 16, 2009
  3. Chase Preuninger

    Date Formats in Excel using POI

    Chase Preuninger, Jul 1, 2010, in forum: Java
    Replies:
    4
    Views:
    1,714
    John B. Matthews
    Jul 3, 2010
  4. vineet.arora3

    CSV to excel using POI

    vineet.arora3, Feb 10, 2011, in forum: Java
    Replies:
    0
    Views:
    870
    vineet.arora3
    Feb 10, 2011
  5. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    231
    Mark Schupp
    Aug 9, 2004
Loading...

Share This Page