poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laubach Shawn Contr OC-ALC/PSB <Shawn.Laub...@tinker.af.mil>
Subject RE: Antwort: RE: Antwort: date value with m/d/yy h:mm:ss AM/PM format
Date Fri, 31 Oct 2003 16:58:05 GMT
I didn't say you missed the point.  Tom missed the getFormat instead of the
getBuiltinFormat.

Shawn

-----Original Message-----
From: andriy.zhurba@bayerbbs.com [mailto:andriy.zhurba@bayerbbs.com]
Sent: Friday, October 31, 2003 10:38 AM
To: POI Users List
Subject: Antwort: RE: Antwort: date value with m/d/yy h:mm:ss AM/PM
format






No I did not.

If you take a builtin format you define it as follows:

HSSFCellStyle cs = wb.createCellStyle();
HSSFDataFormat df = wb.createDataFormat();
cs.setDataFormat(df.getBuiltinFormat("#,##0"));

In Tom's case it is getFormat("") that he should use.

Only the string parameter for getFormat varies.


Regards,
Andrew



|---------+----------------------------->
|         |                             |
|         |                             |
|         |                             |
|         |                             |
|         |                             |
|         |                             |
|         |  Laubach Shawn Contr        |
|         |  OC-ALC/PSB                 |
|         |  <Shawn.Laubach@tinker.af.mi|
|         |  l>                         |
|         |  Received :  31.10.2003     |
|         |  16:59                      |
|         |  Bitte antworten an "POI    |
|         |  Users List"                |
|         |                             |
|---------+----------------------------->
 
>---------------------------------------------------------------------------
----------------------------------------------------|
  |
|
  |
|
  |        An:      'POI Users List' <poi-user@jakarta.apache.org>
|
  |        Kopie:
|
  |        Thema:   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:dist_mec@hotmail.com]
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: <andriy.zhurba@bayerbbs.com>
To: "POI Users List" <poi-user@jakarta.apache.org>
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"                    |
> |         |  <dist_mec@hotmail.com>   |
> |         |  Received :  31.10.2003   |
> |         |  03:26                    |
> |         |  Bitte antworten an "POI  |
> |         |  Users List"              |
> |         |                           |
> |---------+--------------------------->
>
>---------------------------------------------------------------------------
----------------------------------------------------|
>   |
|
>   |
|
>   |        An:      <poi-user@jakarta.apache.org>
|
>   |        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: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
>
>

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

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





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

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


Mime
View raw message