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:[EMAIL PROTECTED]
Sent: Thursday, October 02, 2003 4:50 AM
To: [EMAIL PROTECTED]
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-pre3-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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to