You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Chaudhary, Harsh" <HC...@amfam.com> on 2008/03/04 21:53:09 UTC

Can we have multiple styles for the same cell?

Hi,

I am writing some POI code and the spreadsheet needs the rows to be
colored in a certain way. For example,

the data looks like:

Index		Value
1		jk
1		oi
2		lkkjhkl
2		iyui
2		iuyjhj
3		ihgh

I would like the rows to be colored like so:

1		jk		(GRAY)
1		oi		(GRAY)

2		lkkjhkl	(White)
2		iyui		(White)
2		iuyjhj	(White)

3		ihgh		(GRAY)

The way I am thining of doing this is:

I have defined a single style called cellStyle.

if(conditionGray)
{
	cellStyle = code to make cell gary;
	cell.setStyle(cellStyle);
}
else
{
	cellStyle = code to make cell white;
	cell.setStyle(cellStyle);
}

Now when I do this, the cell colors do not change. This leads me to
believe that maybe its not possible to change the style of a cell once
it has been initialized. Is this true?

If not, how do I go about doing this? I would appreciate your help on
this.

Thanks,
HC.

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


Re: Can we have multiple styles for the same cell?

Posted by Anthony Andrews <py...@yahoo.com>.
You need to create more that one cell style and then apply the relevant one to the cell based upon your condition. So, in pseudocode;

Create grey cell style.
Create white cell style.

if condition
   apply gree cell style to cell
else
   apply white cell style to cell.



"Chaudhary, Harsh" <HC...@amfam.com> wrote: Hi,

I am writing some POI code and the spreadsheet needs the rows to be
colored in a certain way. For example,

the data looks like:

Index  Value
1  jk
1  oi
2  lkkjhkl
2  iyui
2  iuyjhj
3  ihgh

I would like the rows to be colored like so:

1  jk  (GRAY)
1  oi  (GRAY)

2  lkkjhkl (White)
2  iyui  (White)
2  iuyjhj (White)

3  ihgh  (GRAY)

The way I am thining of doing this is:

I have defined a single style called cellStyle.

if(conditionGray)
{
 cellStyle = code to make cell gary;
 cell.setStyle(cellStyle);
}
else
{
 cellStyle = code to make cell white;
 cell.setStyle(cellStyle);
}

Now when I do this, the cell colors do not change. This leads me to
believe that maybe its not possible to change the style of a cell once
it has been initialized. Is this true?

If not, how do I go about doing this? I would appreciate your help on
this.

Thanks,
HC.

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



       
---------------------------------
Never miss a thing.   Make Yahoo your homepage.