my mistake. i did miss the "getFormat()".

thanks andrew and shaun.

----- Original Message ----- 
From: "Laubach Shawn Contr OC-ALC/PSB" <[EMAIL PROTECTED]>
To: "'POI Users List'" <[EMAIL PROTECTED]>
Sent: Friday, October 31, 2003 7:59 AM
Subject: RE: Antwort: date value with m/d/yy h:mm:ss AM/PM format


> You missed the point.  He's not trying to grab a builtin format.  He's
> creating a format object and asking for the given format.  You can do the
> following (this is a copy of his code example with one change).
>
> > HSSFCellStyle cs = wb.createCellStyle();
> > HSSFDataFormat df = wb.createDataFormat();
> > cs.setDataFormat(df.getFormat("m/d/yy h:mm:ss AM/PM"));
>
> Below is a full example that will run and produce a file with a date in
the
> proper format (this is a merge of the date cell example and the custom
data
> format example off the web site):
>
> import org.apache.poi.hssf.usermodel.*;
> import java.util.*;
> import java.io.*;
>
> public class test {
>
>     public static void main(String args[]) throws Exception {
> HSSFWorkbook wb = new HSSFWorkbook();
>     HSSFSheet sheet = wb.createSheet("new sheet");
>
>     // Create a row and put some cells in it. Rows are 0 based.
>     HSSFRow row = sheet.createRow((short)0);
>
>     // Create a cell and put a date value in it.  The first cell is not
> styled
>     // as a date.
>     HSSFCell cell = row.createCell((short)0);
>     cell.setCellValue(new Date());
>
>     // we style the second cell as a date (and time).  It is important to
>     // create a new cell style from the workbook otherwise you can end up
>     // modifying the built in style and effecting not only this cell but
> other cells.
>
>     HSSFCellStyle cellStyle = wb.createCellStyle();
>     HSSFDataFormat format = wb.createDataFormat();
>     cellStyle.setDataFormat(format.getFormat("m/d/yy h:mm:ss AM/PM"));
>     cell = row.createCell((short)1);
>     cell.setCellValue(new Date());
>     cell.setCellStyle(cellStyle);
>
>     // Write the output to a file
>     FileOutputStream fileOut = new FileOutputStream("workbook.xls");
>     wb.write(fileOut);
>     fileOut.close();
>     }
> }
>
> Shawn
>
> -----Original Message-----
> From: Tom [mailto:[EMAIL PROTECTED]
> Sent: Friday, October 31, 2003 9:48 AM
> To: POI Users List
> Subject: Re: Antwort: date value with m/d/yy h:mm:ss AM/PM format
>
>
> that is exactly the problem. i see a  "h:mm:ss AM/PM"  format and a
> "m/d/yy h:mm" .
>
> both formats have most of but not all the precision/fields that i want.
>
> how can i get a "combined" format?
>
> ----- Original Message ----- 
> From: <[EMAIL PROTECTED]>
> To: "POI Users List" <[EMAIL PROTECTED]>
> Sent: Friday, October 31, 2003 12:00 AM
> Subject: Antwort: date value with m/d/yy h:mm:ss AM/PM format
>
>
> >
> >
> >
> >
> > Hello,
> >
> > I use it this way:
> >
> > HSSFCellStyle cs = wb.createCellStyle();
> > HSSFDataFormat df = wb.createDataFormat();
> > cs.setDataFormat(df.getFormat("dd.MM.yyyy"));
> >
> > Though you have to find a string representing your "m/d/yy h:mm:ss
AM/PM"
> > format.
> >
> > Hope this helps.
> >
> > Regards,
> > Andrew
> >
> >
> >
> > |---------+--------------------------->
> > |         |                           |
> > |         |                           |
> > |         |                           |
> > |         |                           |
> > |         |                           |
> > |         |                           |
> > |         |  "Tom"                    |
> > |         |  <[EMAIL PROTECTED]>   |
> > |         |  Received :  31.10.2003   |
> > |         |  03:26                    |
> > |         |  Bitte antworten an "POI  |
> > |         |  Users List"              |
> > |         |                           |
> > |---------+--------------------------->
> >
>
>---------------------------------------------------------------------------
> ----------------------------------------------------|
> >   |
> |
> >   |
> |
> >   |        An:      <[EMAIL PROTECTED]>
> |
> >   |        Kopie:
>                                                |
> >   |        Thema:   date value  with m/d/yy  h:mm:ss AM/PM format
> |
> >
>
>---------------------------------------------------------------------------
> ----------------------------------------------------|
> >
> >
> >
> >
> > i would like to wite write a date value to a cell with "m/d/yy h:mm:ss
> AM/PM"
> > format. i dont see such a format available in the builtinFormats. how
can
> i use
> > either user-defined-formats or composite formats?
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to