poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Beardsley <markbrd...@tiscali.co.uk>
Subject Re: Set cell type to "Date"
Date Mon, 05 Mar 2012 16:02:52 GMT
There is no way to explicitly set a cell as a date type; all date are simply
numeric values which Excel formats so that they appear to be dates. It is
the standard idiom when using POI to do exactly as you are; create a format
and apply that to the cell. Excel and OpenOffice do many things quite
differently and I am not surprised to hear this is one of them; they are not
directly comparable.

Is there a specific reason why you need the type to show as a date when you
open the workbook using Excel? I think I am correct in saying that any date
you create in this way using POI will function correctly if used in any
mathmatical operation on the sheet.

If it is critical to have the Date type then you might want to try a trick -
one that I cannot promise will work. Create an Excel workbook with a sheet
that contains a cell set to type date and with the correct format applied.
Open the workbook using POI, get a reference to the sheet and read the cell
in question from that. Once you have the cell, get the style applied to it
and try applying that same style to other cells to see what happens. It
maybe the case that this will circumvent the 'problem' but I cannot promise
as I have never tried it out myself. Alternatively, find out exactly what
format string is applied to a cell by Excel when you select the date option
and try using that as the format string in POI. Again, I have never tried
this and cannot promise it will work.

View this message in context: http://apache-poi.1045710.n5.nabble.com/Set-cell-type-to-Date-tp5537937p5537985.html
Sent from the POI - User mailing list archive at Nabble.com.

To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org

View raw message