You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by John Byrne <jb...@snbw.org> on 2008/08/21 19:44:54 UTC
Which format do I use for time?
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
RE: Which format do I use for time?
Posted by John Byrne <jb...@snbw.org>.
Thank you,
I found the right formatting in the class documentation.
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
-----Original Message-----
From: Anthony Andrews [mailto:pythonaddict@yahoo.com]
Sent: Thursday, August 21, 2008 11:49 PM
To: POI Users List
Subject: Re: Which format do I use for time?
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 <jb...@snbw.org> wrote:
From: John Byrne <jb...@snbw.org>
Subject: Which format do I use for time?
To: user@poi.apache.org
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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Which format do I use for time?
Posted by Anthony Andrews <py...@yahoo.com>.
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 <jb...@snbw.org> wrote:
From: John Byrne <jb...@snbw.org>
Subject: Which format do I use for time?
To: user@poi.apache.org
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