You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by shankarrao <sh...@gmail.com> on 2011/02/06 16:02:09 UTC
Reusing of Fonts and CellStyles
Hi,
Could you please clarify me on reusing the existing CellStyle properties for
the new CellStyle and add new properties to the new CellStyle?
I have defined a Font by name "myFont" with the font properties.
Then, i created a CellStyle by name "myCellStyle" and set the font "myFont"
to this CellStyle, as given below.
Font myFont = workbook.createFont();
myFont.setFontHeightInPoints((short)10);
myFont.setFontName("Arial");
CellStyle myCellStyle = workbook.createCellStyle();
myCellStyle.setWrapText(true);
myCellStyle.setLocked(true);
myCellStyle.setFont(myFont);
Say if i have to create a new CellStyle which needs to have the properties
that are already defined in the above CellStyle "myCellStyle " and alongside
this i also want to add additional properties to the new CellStyle. In other
words, can i do the following:
//Associate the already defined CellStyle to the newCellStyle
CellStyle newCellStyle = myCellStyle ;
//Add more properties to newCellStyle
newCellStyle.setBorderTop(CellStyle.BORDER_THIN);
newCellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
newCellStyle.setBorderRight(CellStyle.BORDER_THIN);
newCellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
newCellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
newCellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
Please let me know your thoughts.
Regards,
Shankar
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Reusing-of-Fonts-and-CellStyles-tp3373245p3373245.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: Reusing of Fonts and CellStyles
Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Nope, you cannot do that. All you are doing is creating what is known as an
alias, where two different variables actaully refer to the same object.
What you need to do is create a deep copy or clone (hint!!! Look through the
javadoc for the CellStyle class) of the original object and modify that.
Yours
Mark B
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Reusing-of-Fonts-and-CellStyles-tp3373245p3373895.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