You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by suriz4u <su...@gmail.com> on 2008/06/09 07:49:41 UTC

Needs clarity about Cell Styles

Hi all
       Iam using cellstyles in POI to generate excel.For formatting
different datatypes iam using different styles.

For example for formatting date iam using  
 HSSFCellStyle csDate = wb.createCellStyle();
Iam creating different cellstyles for different datatypes.I tried to use
only one cellStyle but it doesnt worked.

Is it recommendable to create different cell styles for different
datatypes???

Please  any one can give me solution for this...

Thanks
Suresh G
-- 
View this message in context: http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17726681.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: Needs clarity about Cell Styles

Posted by Anthony Andrews <py...@yahoo.com>.
Yes, it is quite straightforward really.

You need to create a style for each different type of cell you will encounter. Imagine for example that you need to style date cells, text cells and numeric cells differently and that you still have the alternate line colouring constraint, then you will need to create six different cell styles;

* Basic date cell stlye
* Alternate colouring date cell style
* Basic text cell style
* Alternate colouring text cell style
* Basic numeric cell style
* Alternate colouring numeric cell style

Then, you need to determine how you will apply these styles. The row number question can be easilly addressed using the modulus operator as you have already done. The cell type issue could surely be addressed when you create the cell - at that time you know what is goint to go into the cell and should be able to determine the cell style appropriately.

--- On Mon, 6/9/08, suriz4u &lt;suriz4u@gmail.com&gt; wrote:
From: suriz4u &lt;suriz4u@gmail.com&gt;
Subject: Re: Needs clarity about Cell Styles
To: user@poi.apache.org
Date: Monday, June 9, 2008, 9:30 PM

Thanks Anthony.But iam using different styles for different objects.For
example for date iam using
HSSFCellStyle csDate = wb.createCellStyle();
HSSFCellStyle csDouble = wb.createCellStyle();
I have different styles for different datatypes such as double etc..
So based on the row count i can set the color,but if iam using following
code.
Iam looping through row and for each cell iam checking the datatype.

 if(value instanceof Double)
                    {
                        if(!(rownum%2==0))
                          {  
                           
csDouble.setFillForegroundColor(HSSFColor.AQUA.index);
                           
csDouble.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
                          }
}
So iam using many styles in a row,i mean for different cells i have
different styles.So if iam using above code and setting color.That color is
being applied through out the sheet.

So any solution please??


Anthony Andrews wrote:
&gt; 
&gt; As far as I know, there is no way to set the style for a row; so, you are
&gt; going to have to set the style for each cell as you create it.
&gt; 
&gt; If it were me. I would create the style objects for each 'row'
firstly,
&gt; outside of any loop. So;
&gt; 
&gt; HSSFCellStyle evenRowCellStyle = wb.createCellStyle();
&gt; evenRowCellStyle.setBackgroundFillColor(HSSFColor.AQUA.index);
&gt; HSSFCellStyle oddRowCellStyle = wb.createCellStyle();
&gt; oddRowCellStyle.setBackgroundFillColor(HSSFColor.RED.index);
&gt; 
&gt; Where wb is the reference to a workbook I have created.
&gt; 
&gt; Now, I do not know how you are creating your cells, but the example I will
&gt; give is of a couple of loops; the outer loop creates rows, the inner
&gt; cells. So;
&gt; 
&gt; HSSFSheet sheet = wb.createSheet("Colouring Test");
&gt; HSSFRow row = null;
&gt; HSSFCell cell = null;
&gt; 
&gt; for (int rowNum = 0; rowNum &amp;lt; 10; rowNum++) {
&gt; 
&gt; &amp;nbsp;&amp;nbsp; row = sheet.createRow((short)rowNum);
&gt; 
&gt; &amp;nbsp;&amp;nbsp; for(int cellNum = 0; cellNum &amp;lt; 10; cellNum++)
{
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cell =
row.createCell((short)colNum);
&gt; 
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if((rowNum % 2) == 0) {
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; cell.setCellStyle(evenRowCellStyle);
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else {
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; cell.setCellStyle(oddRowCellStyle);
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&gt; &amp;nbsp;&amp;nbsp; }
&gt; 
&gt; }
&gt; 
&gt; You may even find that you only need to create a single cell style object,
&gt; try it on a small test sheet and see.
&gt; 
&gt; PS - Hope this works, I did not test it simple typed the code into the
&gt; browser. If not, just let me know.
&gt; 
&gt; 
&gt; --- On Mon, 6/9/08, suriz4u &amp;lt;suriz4u@gmail.com&amp;gt; wrote:
&gt; From: suriz4u &amp;lt;suriz4u@gmail.com&amp;gt;
&gt; Subject: Re: Needs clarity about Cell Styles
&gt; To: user@poi.apache.org
&gt; Date: Monday, June 9, 2008, 2:40 AM
&gt; 
&gt; Thanks for such a good explanation.But in my application there is
&gt; requirement that alternative rows should be colored.As iam using different
&gt; styles for different objects.I tried to use in following way for different
&gt; objects
&gt; 
&gt;  HSSFCellStyle csDouble= wb.createCellStyle();
&gt;   if(!(rowNumber%2==0)) 
&gt;        csDouble.setFillBackgroundColor(HSSFColor.AQUA.index);
&gt; 
&gt; But it didnt worked in this way..
&gt; Is there any  solution for this???
&gt; 
&gt; 
&gt; 
&gt; 
&gt; 
&gt; Anthony Andrews wrote:
&gt; &amp;gt; 
&gt; &amp;gt; Yes, you need to create a different style object for each cell
style
&gt; that
&gt; &amp;gt; your sheet requires. Typically, people tend to accomplish this
task
&gt; at the
&gt; &amp;gt; start of the application - assuming of course they know at that
stage
&gt; all
&gt; &amp;gt; of the cell styles they require. This is not to say, of course,
that
&gt; there
&gt; &amp;gt; is anything wrong with creating styles as you go, just try to
avoid
&gt; &amp;gt; duplicates if memory could be an issue for you.
&gt; &amp;gt; 
&gt; &amp;gt; If you do try to reuse cell styles by modifying the style object
once
&gt; it
&gt; &amp;gt; has been created, you will (should) find that all of your cells
will
&gt; have
&gt; &amp;gt; the same appearance. This occurs because the cell style objects
are
&gt; &amp;gt; interpreted (interrogated) when you call the write method if I
&gt; understand
&gt; &amp;gt; correctly.
&gt; &amp;gt; 
&gt; &amp;gt; --- On Sun, 6/8/08, suriz4u
&amp;amp;lt;suriz4u@gmail.com&amp;amp;gt; wrote:
&gt; &amp;gt; From: suriz4u &amp;amp;lt;suriz4u@gmail.com&amp;amp;gt;
&gt; &amp;gt; Subject: Needs clarity about Cell Styles
&gt; &amp;gt; To: user@poi.apache.org
&gt; &amp;gt; Date: Sunday, June 8, 2008, 10:49 PM
&gt; &amp;gt; 
&gt; &amp;gt; Hi all
&gt; &amp;gt;        Iam using cellstyles in POI to generate excel.For
formatting
&gt; &amp;gt; different datatypes iam using different styles.
&gt; &amp;gt; 
&gt; &amp;gt; For example for formatting date iam using  
&gt; &amp;gt;  HSSFCellStyle csDate = wb.createCellStyle();
&gt; &amp;gt; Iam creating different cellstyles for different datatypes.I tried
to
&gt; use
&gt; &amp;gt; only one cellStyle but it doesnt worked.
&gt; &amp;gt; 
&gt; &amp;gt; Is it recommendable to create different cell styles for different
&gt; &amp;gt; datatypes???
&gt; &amp;gt; 
&gt; &amp;gt; Please  any one can give me solution for this...
&gt; &amp;gt; 
&gt; &amp;gt; Thanks
&gt; &amp;gt; Suresh G
&gt; &amp;gt; -- 
&gt; &amp;gt; View this message in context:
&gt; &amp;gt;
&gt;
http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17726681.html
&gt; &amp;gt; Sent from the POI - User mailing list archive at Nabble.com.
&gt; &amp;gt; 
&gt; &amp;gt; 
&gt; &amp;gt;
---------------------------------------------------------------------
&gt; &amp;gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; &amp;gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; &amp;gt; 
&gt; &amp;gt; 
&gt; &amp;gt;       
&gt; &amp;gt; 
&gt; 
&gt; -- 
&gt; View this message in context:
&gt;
http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17729434.html
&gt; Sent from the POI - User mailing list archive at Nabble.com.
&gt; 
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; 
&gt; 
&gt;       
&gt; 

-- 
View this message in context:
http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17747584.html
Sent from the POI - User mailing list archive at Nabble.com.


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


      

Re: Needs clarity about Cell Styles

Posted by suriz4u <su...@gmail.com>.
Thanks Anthony.But iam using different styles for different objects.For
example for date iam using
HSSFCellStyle csDate = wb.createCellStyle();
HSSFCellStyle csDouble = wb.createCellStyle();
I have different styles for different datatypes such as double etc..
So based on the row count i can set the color,but if iam using following
code.
Iam looping through row and for each cell iam checking the datatype.

 if(value instanceof Double)
                    {
                        if(!(rownum%2==0))
                          {  
                           
csDouble.setFillForegroundColor(HSSFColor.AQUA.index);
                           
csDouble.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
                          }
}
So iam using many styles in a row,i mean for different cells i have
different styles.So if iam using above code and setting color.That color is
being applied through out the sheet.

So any solution please??


Anthony Andrews wrote:
> 
> As far as I know, there is no way to set the style for a row; so, you are
> going to have to set the style for each cell as you create it.
> 
> If it were me. I would create the style objects for each 'row' firstly,
> outside of any loop. So;
> 
> HSSFCellStyle evenRowCellStyle = wb.createCellStyle();
> evenRowCellStyle.setBackgroundFillColor(HSSFColor.AQUA.index);
> HSSFCellStyle oddRowCellStyle = wb.createCellStyle();
> oddRowCellStyle.setBackgroundFillColor(HSSFColor.RED.index);
> 
> Where wb is the reference to a workbook I have created.
> 
> Now, I do not know how you are creating your cells, but the example I will
> give is of a couple of loops; the outer loop creates rows, the inner
> cells. So;
> 
> HSSFSheet sheet = wb.createSheet("Colouring Test");
> HSSFRow row = null;
> HSSFCell cell = null;
> 
> for (int rowNum = 0; rowNum &lt; 10; rowNum++) {
> 
> &nbsp;&nbsp; row = sheet.createRow((short)rowNum);
> 
> &nbsp;&nbsp; for(int cellNum = 0; cellNum &lt; 10; cellNum++) {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell = row.createCell((short)colNum);
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if((rowNum % 2) == 0) {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> cell.setCellStyle(evenRowCellStyle);
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> cell.setCellStyle(oddRowCellStyle);
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
> &nbsp;&nbsp; }
> 
> }
> 
> You may even find that you only need to create a single cell style object,
> try it on a small test sheet and see.
> 
> PS - Hope this works, I did not test it simple typed the code into the
> browser. If not, just let me know.
> 
> 
> --- On Mon, 6/9/08, suriz4u &lt;suriz4u@gmail.com&gt; wrote:
> From: suriz4u &lt;suriz4u@gmail.com&gt;
> Subject: Re: Needs clarity about Cell Styles
> To: user@poi.apache.org
> Date: Monday, June 9, 2008, 2:40 AM
> 
> Thanks for such a good explanation.But in my application there is
> requirement that alternative rows should be colored.As iam using different
> styles for different objects.I tried to use in following way for different
> objects
> 
>  HSSFCellStyle csDouble= wb.createCellStyle();
>   if(!(rowNumber%2==0)) 
>        csDouble.setFillBackgroundColor(HSSFColor.AQUA.index);
> 
> But it didnt worked in this way..
> Is there any  solution for this???
> 
> 
> 
> 
> 
> Anthony Andrews wrote:
> &gt; 
> &gt; Yes, you need to create a different style object for each cell style
> that
> &gt; your sheet requires. Typically, people tend to accomplish this task
> at the
> &gt; start of the application - assuming of course they know at that stage
> all
> &gt; of the cell styles they require. This is not to say, of course, that
> there
> &gt; is anything wrong with creating styles as you go, just try to avoid
> &gt; duplicates if memory could be an issue for you.
> &gt; 
> &gt; If you do try to reuse cell styles by modifying the style object once
> it
> &gt; has been created, you will (should) find that all of your cells will
> have
> &gt; the same appearance. This occurs because the cell style objects are
> &gt; interpreted (interrogated) when you call the write method if I
> understand
> &gt; correctly.
> &gt; 
> &gt; --- On Sun, 6/8/08, suriz4u &amp;lt;suriz4u@gmail.com&amp;gt; wrote:
> &gt; From: suriz4u &amp;lt;suriz4u@gmail.com&amp;gt;
> &gt; Subject: Needs clarity about Cell Styles
> &gt; To: user@poi.apache.org
> &gt; Date: Sunday, June 8, 2008, 10:49 PM
> &gt; 
> &gt; Hi all
> &gt;        Iam using cellstyles in POI to generate excel.For formatting
> &gt; different datatypes iam using different styles.
> &gt; 
> &gt; For example for formatting date iam using  
> &gt;  HSSFCellStyle csDate = wb.createCellStyle();
> &gt; Iam creating different cellstyles for different datatypes.I tried to
> use
> &gt; only one cellStyle but it doesnt worked.
> &gt; 
> &gt; Is it recommendable to create different cell styles for different
> &gt; datatypes???
> &gt; 
> &gt; Please  any one can give me solution for this...
> &gt; 
> &gt; Thanks
> &gt; Suresh G
> &gt; -- 
> &gt; View this message in context:
> &gt;
> http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17726681.html
> &gt; Sent from the POI - User mailing list archive at Nabble.com.
> &gt; 
> &gt; 
> &gt; ---------------------------------------------------------------------
> &gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> &gt; For additional commands, e-mail: user-help@poi.apache.org
> &gt; 
> &gt; 
> &gt;       
> &gt; 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17729434.html
> Sent from the POI - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
>       
> 

-- 
View this message in context: http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17747584.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: Needs clarity about Cell Styles

Posted by Anthony Andrews <py...@yahoo.com>.
As far as I know, there is no way to set the style for a row; so, you are going to have to set the style for each cell as you create it.

If it were me. I would create the style objects for each 'row' firstly, outside of any loop. So;

HSSFCellStyle evenRowCellStyle = wb.createCellStyle();
evenRowCellStyle.setBackgroundFillColor(HSSFColor.AQUA.index);
HSSFCellStyle oddRowCellStyle = wb.createCellStyle();
oddRowCellStyle.setBackgroundFillColor(HSSFColor.RED.index);

Where wb is the reference to a workbook I have created.

Now, I do not know how you are creating your cells, but the example I will give is of a couple of loops; the outer loop creates rows, the inner cells. So;

HSSFSheet sheet = wb.createSheet("Colouring Test");
HSSFRow row = null;
HSSFCell cell = null;

for (int rowNum = 0; rowNum &lt; 10; rowNum++) {

&nbsp;&nbsp; row = sheet.createRow((short)rowNum);

&nbsp;&nbsp; for(int cellNum = 0; cellNum &lt; 10; cellNum++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell = row.createCell((short)colNum);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if((rowNum % 2) == 0) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell.setCellStyle(evenRowCellStyle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell.setCellStyle(oddRowCellStyle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp; }

}

You may even find that you only need to create a single cell style object, try it on a small test sheet and see.

PS - Hope this works, I did not test it simple typed the code into the browser. If not, just let me know.


--- On Mon, 6/9/08, suriz4u &lt;suriz4u@gmail.com&gt; wrote:
From: suriz4u &lt;suriz4u@gmail.com&gt;
Subject: Re: Needs clarity about Cell Styles
To: user@poi.apache.org
Date: Monday, June 9, 2008, 2:40 AM

Thanks for such a good explanation.But in my application there is
requirement that alternative rows should be colored.As iam using different
styles for different objects.I tried to use in following way for different
objects

 HSSFCellStyle csDouble= wb.createCellStyle();
  if(!(rowNumber%2==0)) 
       csDouble.setFillBackgroundColor(HSSFColor.AQUA.index);

But it didnt worked in this way..
Is there any  solution for this???





Anthony Andrews wrote:
&gt; 
&gt; Yes, you need to create a different style object for each cell style that
&gt; your sheet requires. Typically, people tend to accomplish this task at the
&gt; start of the application - assuming of course they know at that stage all
&gt; of the cell styles they require. This is not to say, of course, that there
&gt; is anything wrong with creating styles as you go, just try to avoid
&gt; duplicates if memory could be an issue for you.
&gt; 
&gt; If you do try to reuse cell styles by modifying the style object once it
&gt; has been created, you will (should) find that all of your cells will have
&gt; the same appearance. This occurs because the cell style objects are
&gt; interpreted (interrogated) when you call the write method if I understand
&gt; correctly.
&gt; 
&gt; --- On Sun, 6/8/08, suriz4u &amp;lt;suriz4u@gmail.com&amp;gt; wrote:
&gt; From: suriz4u &amp;lt;suriz4u@gmail.com&amp;gt;
&gt; Subject: Needs clarity about Cell Styles
&gt; To: user@poi.apache.org
&gt; Date: Sunday, June 8, 2008, 10:49 PM
&gt; 
&gt; Hi all
&gt;        Iam using cellstyles in POI to generate excel.For formatting
&gt; different datatypes iam using different styles.
&gt; 
&gt; For example for formatting date iam using  
&gt;  HSSFCellStyle csDate = wb.createCellStyle();
&gt; Iam creating different cellstyles for different datatypes.I tried to use
&gt; only one cellStyle but it doesnt worked.
&gt; 
&gt; Is it recommendable to create different cell styles for different
&gt; datatypes???
&gt; 
&gt; Please  any one can give me solution for this...
&gt; 
&gt; Thanks
&gt; Suresh G
&gt; -- 
&gt; View this message in context:
&gt;
http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17726681.html
&gt; Sent from the POI - User mailing list archive at Nabble.com.
&gt; 
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; 
&gt; 
&gt;       
&gt; 

-- 
View this message in context:
http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17729434.html
Sent from the POI - User mailing list archive at Nabble.com.


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


      

Re: Needs clarity about Cell Styles

Posted by suriz4u <su...@gmail.com>.

Thanks for such a good explanation.But in my application there is
requirement that alternative rows should be colored.As iam using different
styles for different objects.I tried to use in following way for different
objects

 HSSFCellStyle csDouble= wb.createCellStyle();
  if(!(rowNumber%2==0)) 
       csDouble.setFillBackgroundColor(HSSFColor.AQUA.index);

But it didnt worked in this way..
Is there any  solution for this???





Anthony Andrews wrote:
> 
> Yes, you need to create a different style object for each cell style that
> your sheet requires. Typically, people tend to accomplish this task at the
> start of the application - assuming of course they know at that stage all
> of the cell styles they require. This is not to say, of course, that there
> is anything wrong with creating styles as you go, just try to avoid
> duplicates if memory could be an issue for you.
> 
> If you do try to reuse cell styles by modifying the style object once it
> has been created, you will (should) find that all of your cells will have
> the same appearance. This occurs because the cell style objects are
> interpreted (interrogated) when you call the write method if I understand
> correctly.
> 
> --- On Sun, 6/8/08, suriz4u &lt;suriz4u@gmail.com&gt; wrote:
> From: suriz4u &lt;suriz4u@gmail.com&gt;
> Subject: Needs clarity about Cell Styles
> To: user@poi.apache.org
> Date: Sunday, June 8, 2008, 10:49 PM
> 
> Hi all
>        Iam using cellstyles in POI to generate excel.For formatting
> different datatypes iam using different styles.
> 
> For example for formatting date iam using  
>  HSSFCellStyle csDate = wb.createCellStyle();
> Iam creating different cellstyles for different datatypes.I tried to use
> only one cellStyle but it doesnt worked.
> 
> Is it recommendable to create different cell styles for different
> datatypes???
> 
> Please  any one can give me solution for this...
> 
> Thanks
> Suresh G
> -- 
> View this message in context:
> http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17726681.html
> Sent from the POI - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
>       
> 

-- 
View this message in context: http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17729434.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: Needs clarity about Cell Styles

Posted by Anthony Andrews <py...@yahoo.com>.
Yes, you need to create a different style object for each cell style that your sheet requires. Typically, people tend to accomplish this task at the start of the application - assuming of course they know at that stage all of the cell styles they require. This is not to say, of course, that there is anything wrong with creating styles as you go, just try to avoid duplicates if memory could be an issue for you.

If you do try to reuse cell styles by modifying the style object once it has been created, you will (should) find that all of your cells will have the same appearance. This occurs because the cell style objects are interpreted (interrogated) when you call the write method if I understand correctly.

--- On Sun, 6/8/08, suriz4u &lt;suriz4u@gmail.com&gt; wrote:
From: suriz4u &lt;suriz4u@gmail.com&gt;
Subject: Needs clarity about Cell Styles
To: user@poi.apache.org
Date: Sunday, June 8, 2008, 10:49 PM

Hi all
       Iam using cellstyles in POI to generate excel.For formatting
different datatypes iam using different styles.

For example for formatting date iam using  
 HSSFCellStyle csDate = wb.createCellStyle();
Iam creating different cellstyles for different datatypes.I tried to use
only one cellStyle but it doesnt worked.

Is it recommendable to create different cell styles for different
datatypes???

Please  any one can give me solution for this...

Thanks
Suresh G
-- 
View this message in context:
http://www.nabble.com/Needs-clarity-about-Cell-Styles-tp17726681p17726681.html
Sent from the POI - User mailing list archive at Nabble.com.


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