John, I think that you are passing the wrong sort of format string to the
getFormat() method.
Take a look at this piece of code I cut from the Apache 'How To' website;
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
cell = row.createCell((short)1);
cell.setCellValue(new Date());
cell.setCellStyle(cellStyle);
Firstly, it uses the HSSFDataFormat class method getBuiltinFormat() and it
requires a different sort of formatting string as you can see. If you look at
the HSSFDataFormat class, there is a formatting string that resembles the
format you require - "h:mm". Furthermore, it is even possible to create your
own formatting string as long as it conforms to the same 'standards' i.e. an h
for hours, m for minutes, s for seconds, etc.
--- On Thu, 8/21/08, John Byrne <[EMAIL PROTECTED]> wrote:
From: John Byrne <[EMAIL PROTECTED]>
Subject: Which format do I use for time?
To: [email protected]
Date: Thursday, August 21, 2008, 10:44 AM
Hello all,
I'm trying to format a time so it does not show just a number (instead
of a time) and I'm not having much luck. Here is the code I'm using:
HSSFWorkbook wb = ec.getWorkbook();
HSSFDataFormat format = wb.createDataFormat();
HSSFCellStyle styleTimeFormat;
styleTimeFormat = wb.createCellStyle();
styleTimeFormat.setDataFormat(format.getFormat("1:30 PM"));
.
.
.
ec.getCell(cellColumn+i).setCellStyle(styleTimeFormat);
.
.
.
Does anyone know what I should enter for the parameter getFormat?
Thank you,
John
John Byrne
Support Network for Battered Women
1257 Tasman Dr. Suite C
Sunnyvale, CA
94089
(408) 541-6100 x 138
Fax: (408) 541-3333