poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MSB <markbrd...@tiscali.co.uk>
Subject RE: How to set different types of fomat and style to different cell
Date Mon, 17 Aug 2009 08:08:47 GMT

Can I check that all you want to do is to change the colour of a cell for
which you have previously created a cell style without affecting any other
cells that style may have been applied to?

If that is the case, then the answer is simple, well fairly, get the style
from the cell, clone or copy that style, modify the attribute(s) you want to
change and then apply the modified style to the cell.

If you look back through the posts made to the list recently, there is one
by another member called yehogold I think. We have been working on something
similar for him and that example also includes a possible style pool; not
saying this IS the answer to your problem but I think it does point a way
forward.

Must go now, I am getting shouted at by my colleagues because we have a long
day ahaead of us pulling himalyan balsam at a local nature reserve. I will
be back later today and if you have any questions post them to the list and
I will look at them then; please do not think that if I do not reply for
while I am ignoring you.

Yours

Mark B


Khanh Tran-3 wrote:
> 
> Hello MSB,
> Thannks for quick answer, but I still run into the next problem.
> 
> Provided that I want to set cell color for a cell, then I:
> cellStyle = workbook.createCellStyle();
> ...
> Cell.setCellStyle(cellStyle);
> 
> And latter, I want to change the color for that cell,
> I get back the cellstyle object that created before and change it's
> properties:
> 
> cellStyle = cell.getCellStyle();
> ....
> 
> The problem is that for some cell(blank cells), getCellStyle() return the
> default cellstyle that are shared with many cells on workbook. Changing
> this
> will affect so many another cells that I don't' want to.
> 
> How can we handle this?
> Thanks
> 
> -----Original Message-----
> From: MSB [mailto:markbrdsly@tiscali.co.uk] 
> Sent: Monday, August 17, 2009 12:37 PM
> To: user@poi.apache.org
> Subject: RE: How to set different types of fomat and style to different
> cell
> 
> 
> Yes, but would this not be the case if you did exactly the same with Excel
> itself? If not, I cannot imagine how the file would be structured; the
> style
> information has to be stored somewhere even if it is only the differences
> from a notaional 'base' style that are stored.
> 
> Yours
> 
> Mark B
> 
> 
> Khanh Tran-3 wrote:
>> 
>> Hello,
>> 
>> What if I programmatically format 500 cells with difference styles?
>> 
>> The target spreadsheet now contains huge number of styles.
>> 
>> Khanh
>> 
>> -----Original Message----
>> 
>>  
>> 
>> 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
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/RE%3A-How-to-set-different-types-of-fomat-and-style-to
> -different-cell-tp25000554p25001251.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
> 
> 
> 
> ---------------------------------------------------------------------
> 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/RE%3A-How-to-set-different-types-of-fomat-and-style-to-different-cell-tp25000554p25002734.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


Mime
View raw message