Date Formats in Excel using POI

  • Thread starter Chase Preuninger
  • Start date
C

Chase Preuninger

I am writing an app where I am simply moving cells from one excel file
to another. The problem is I need to keep the date formats exactly as
they appear in the original. For example "9/12/2005" !=
"09/12/2005". These dates are not in a consistent format as well.
How can I transfer the formats.
 
L

Lew

I am writing an app where I am simply moving cells from one excel file
to another. The problem is I need to keep the date formats exactly as
they appear in the original. For example "9/12/2005" !=
"09/12/2005". These dates are not in a consistent format as well.
How can I transfer the formats.

Make sure the destination CellStyle is the same as that of the source.

I'm new to POI myself.
 
C

Chase Preuninger

I did that. I called something like
cell.getCellStyle().cloneStyleFrom(otherCell.getCellStyle()); It is
just very slow so I never go to see if it works.
 
C

Chase Preuninger

Here is my actual code and it still comes across as a number and not a
date in the output.

newCell.getCellStyle().cloneStyleFrom(currentCell.getCellStyle());
 
J

John B. Matthews

Chase Preuninger said:
Here is my actual code and it still comes across as a number and not
a date in the output.

newCell.getCellStyle().cloneStyleFrom(currentCell.getCellStyle());

I haven't used the cloneStyleFrom() method, but here's a snippet I use
to see the format index and string;

private static String getFormat(Cell cell) {
return " ["
+ cell.getCellStyle().getDataFormat()
+ ":"
+ cell.getCellStyle().getDataFormatString()
+ "]";
}

Also, I see that columns can have separate formats.
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top