All:
I'm a newbie at using POI (using 3.0.2 mostly because that's the latest
Spring works with) and it seemed really sensible until I hit this
roadblock. I can create a cell just fine (working with the HSSF classes,
as that's the form appropriate for my client), but when I try to create
a date-formatted cell, no formatting seems to work at all! I've tried
the built-in date/time formats in HSSFDataFormat, custom formats, the
works. All I get is something like "40973.28833" every time. The cell
comes up as a General cell, not a Date cell (or even, as I set it at one
point, as a numeric cell - as you can see below, I tried also not
setting it at all, and that didn't help either).
My code looks like this:
HSSFCellStyle cellStyle =
workbook.createCellStyle();
HSSFDataFormat formatter =
workbook.createDataFormat();
short idx = formatter.getFormat(dateFormat);
if (idx > -1)
{
cellStyle.setDataFormat(idx);
// cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue((Date) o);
}
else
{
String s = dataCell.getValue(rowcount, data);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(new HSSFRichTextString(s));
}
Has anyone any ideas? I have looked through the mailing list archives
and couldn't see anyone else having this problem, so it must be
something I'm doing wrong. I would greatly appreciate any help anyone
can give me. I can obviously format the date as a String, but then it
won't sort correctly in Excel, I wouldn't imagine.
Thanks!
David Sills