You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Ravi Sundaar <rs...@hotmail.com> on 2008/09/26 14:54:46 UTC

problem with HSSFStyle?

Hi,
 
I have a question about the HSSFStyle object: 
 
I need to change the style for a few cells in my spreadsheet - setting a thick border and so on. However, when I try that the style gets applied to the whole spreadsheet!! Even if I set the style for just for one cell, it seems to apply it to all cells.
 
 
Here is the code snippet that does that:
 
 int col = 10;
  for (int i = startRow; i <= endRow; i++)
  {   HSSFCell cell = sheet.getRow(i).getCell(col, HSSFRow.CREATE_NULL_AS_BLANK);   HSSFCellStyle style = cell.getCellStyle();   style.setBorderRight(HSSFCellStyle.BORDER_THICK);   style.getRightBorderColor();   cell.setCellStyle(style);  }
 
What am I doing wrong? Is there a workaround?
 
Thanks,
Ravi.
_________________________________________________________________
Want to do more with Windows Live? Learn “10 hidden secrets” from Jamie.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008

Re: problem with HSSFStyle?

Posted by Pierre Lavignotte <pi...@gmail.com>.
Hello Ravi,

That's because one style can be applied to several cells.
Excel is "clever" and save style objects when they are equals.

So you have to clone the HSSFStyle that you find in the cell, update it, and
set it again in your cell
If you want to apply the same change to all you cells, you can also keep
this clone and set it in all your cells.

I don't remember but there is a specific method to clone the cell style.

Pierre

On Fri, Sep 26, 2008 at 2:54 PM, Ravi Sundaar <rs...@hotmail.com> wrote:

> Hi,
>
> I have a question about the HSSFStyle object:
>
> I need to change the style for a few cells in my spreadsheet - setting a
> thick border and so on. However, when I try that the style gets applied to
> the whole spreadsheet!! Even if I set the style for just for one cell, it
> seems to apply it to all cells.
>
>
> Here is the code snippet that does that:
>
>  int col = 10;
>  for (int i = startRow; i <= endRow; i++)
>  {   HSSFCell cell = sheet.getRow(i).getCell(col,
> HSSFRow.CREATE_NULL_AS_BLANK);   HSSFCellStyle style = cell.getCellStyle();
>   style.setBorderRight(HSSFCellStyle.BORDER_THICK);
> style.getRightBorderColor();   cell.setCellStyle(style);  }
>
> What am I doing wrong? Is there a workaround?
>
> Thanks,
> Ravi.
> _________________________________________________________________
> Want to do more with Windows Live? Learn "10 hidden secrets" from Jamie.
>
> http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008<http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns%21550F681DAD532637%215295.entry?ocid=TXT_TAGLM_WL_domore_092008>




-- 
Cordialement,
Pierre Lavignotte
Ingénieur Conception & Développement
http://pierre.lavignotte.googlepages.com

Re: problem with HSSFStyle?

Posted by Nick Burch <ni...@torchbox.com>.
On Fri, 26 Sep 2008, Ravi Sundaar wrote:
> I need to change the style for a few cells in my spreadsheet - setting a 
> thick border and so on. However, when I try that the style gets applied 
> to the whole spreadsheet!!

Clearly your cell is set to use the default cell style. So, when you get 
the cell style, it's the default one, and you change that. poi is behaving 
as expected

You probably want to create a new cell style, set it up as you want, then 
apply it to only certain cells. See the docs for more info

Nick

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


Re: Does setCellType work?

Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 16 Oct 2008, Ravi Sundaar wrote:
> I have a requirement to set the cell type to Number, with a certain 
> precision.
>
> So, after creating a cell, I set the cell type to CELL_TYPE_NUMERIC and 
> then try to set the precision.

The cell type is something like number or string or formula, and is a 
somewhat low level thing

I think you're confusing cell type and cell formatting. Take a look at the 
poi site for how to do the latter

Nick

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


Does setCellType work?

Posted by Ravi Sundaar <rs...@hotmail.com>.
Hi,
 
I have a requirement to set the cell type to Number, with a certain precision. 
So, after creating a cell, I set the cell type to CELL_TYPE_NUMERIC and then try to set the precision. Unfortunately, when I look at the spreadsheet, the cell type is still "General".
 
Any clues?
 
Thanks,
Ravi.
_________________________________________________________________
When your life is on the go—take your life with you.
http://clk.atdmt.com/MRT/go/115298558/direct/01/