From: Chase Preuninger on
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.
From: Lew on
On 07/01/2010 12:40 AM, Chase Preuninger wrote:
> 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.

--
Lew
From: Chase Preuninger on
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.
From: Chase Preuninger on
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());
From: John B. Matthews on
In article
<7e1dc5e8-bb3f-4486-abf2-c7128dacd42e(a)k1g2000prl.googlegroups.com>,
Chase Preuninger <chasepreuninger(a)gmail.com> wrote:

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

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>