You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Mehner, Björn" <Bj...@epos-cs.de> on 2003/10/02 09:03:55 UTC

AW: How to set different types of fomat and style to different ce ll

yes that is true. You are always modifing the same java object, which
effects all the cells using this
object. Best is to create as many style objects as you have diffrent
sorts of styles. One for percentage, one for floating point numbers and
so on.

bye Bodo

> -----Ursprüngliche Nachricht-----
> Von: Robert Lowe [mailto:rmlowe@rmlowe.com]
> Gesendet: Mittwoch, 1. Oktober 2003 23:49
> An: POI Users List
> Betreff: RE: How to set different types of fomat and style to 
> different
> cell
> 
> 
> A cellstyle can be "shared" by many cells in a workbook. 
> Currently you are
> modifying the "shared" cellstyle, and this affects all cells 
> that use that
> style.
> 
> Instead, try to create a new style using 
> HSSFWorkbook.createCellStyle(), and
> then use cell.setCellStyle(HSSFCellStyle).
> 
> In other words, replace:
> 
>                   HSSFCellStyle cellStyle = cell.getCellStyle();
> 
> with:
> 
>                   HSSFCellStyle cellStyle = 
> workbook.createCellStyle();
>                   cell.setCellStyle(cellStyle);
> 
> - Rob
> 
> 
> -----Original Message-----
> From: Prashant Patel [mailto:ppatel@lukensgroup.com]
> Sent: Thursday, October 02, 2003 4:50 AM
> To: poi-user@jakarta.apache.org
> Subject: How to set different types of fomat and style to 
> different cell
> 
> 
> 
> 
> How can I set different types of format (i.e percentage, general,
> Numeric with 2 or 3 decimal places) and style for different cells in
> same worksheet? I used following code to set different format for
> different cell, but it applies whatever format I set in the 
> last cell to
> all cells in the worksheet.
> 
> 
> 
>                   HSSFCellStyle cellStyle = cell.getCellStyle();
> 
>                   if(formatType == 1)
> 
>                         cellStyle.setDataFormat((short)1); 
> //Format -->
> "0"
> 
>                   else if(formatType == 4)
> 
>                         cellStyle.setDataFormat((short)4); 
> //Format -->
> "#,##0.00"
> 
>                   else if(formatType == 0xa)
> 
>                         cellStyle.setDataFormat((short)0xa); //Format
> --> "0.00%"
> 
>                   else if(formatType == 0x11)
> 
>                         cellStyle.setDataFormat((short)0xa); //Format
> --> "mmm-yy"
> 
>                   else
> 
>                         cellStyle.setDataFormat((short)0); 
> //Format -->
> General
> 
> 
> 
> 
> 
> I noticed that createCellStyle
> <file:///C:\Lukens\TVA\Jakarta%20-%20POI%201.5.1\poi-bin-2.0-p
re3-200307
28\docs\apidocs\org\apache\poi\hssf\usermodel\HSSFWorkbook.html#createCe
llStyle()> () and createDataFormat
<file:///C:\Lukens\TVA\Jakarta%20-%20POI%201.5.1\poi-bin-2.0-pre3-200307
28\docs\apidocs\org\apache\poi\hssf\usermodel\HSSFWorkbook.html#createDa
taFormat()> () API only available in the HSSFWorkbook class. If each
cell can have its own format and style, shouldn't these API be in
HSSFCell class?





Thanks in advance.

Prashant Patel






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