hi nick,
ignore my last message about cell text changing a cell style. I am still
working on copying a cell style but taking into account what you said about
using a hastable. This is the code i have so far:
Map<HSSFCellStyle,HSSFCellStyle> wbStyles = new
HashMap<HSSFCellStyle,HSSFCellStyle>();
...
HSSFCellStyle cellNewStyle = setStyle(book, cellOld);
cellNew.setCellStyle(cellNewStyle);
...
private HSSFCellStyle setStyle(HSSFWorkbook book, HSSFCell cellold){
HSSFCellStyle oldStyle = cellold.getCellStyle();
HSSFCellStyle newStyle = null;
try{
// no styles create style for workbook and add to Map
if(wbStyles.isEmpty()){
newStyle = book.createCellStyle();
newStyle.cloneStyleFrom(oldStyle);
wbStyles.put(oldStyle, newStyle);
}
else{
// check that the style doesn't already exist
for(int i = 0; i<wbStyles.size(); i++){
newStyle = wbStyles.get(oldStyle);
// get style if it already exists
if(newStyle.equals(oldStyle)){
log.info("The styles match");
}
// create new style if the style doesn't exist
else{
log.info("The styles do not match");
}
}
}
}
catch(Exception e){
l og.error("setStyle() error: " + e.toString());
}
return newStyle;
}
At the moment all i want to do is display a message when the cell styles
match. However, this never happens. Before i clone the style the
field_1_font_index of oldStyle is 20 but when this is cloned the
field_1_font_index of newStyle is changed to 5 therefore i the oldstyle and
newstyle will never be the same. What is causing the field_1 to change from
20 to 5 when it is cloned?
many thanks
mark
Nick Burch wrote:
>
> On Tue, 15 Jul 2008, mjw_85uk wrote:
>> i have solved the people of java.lang.NoSuchMethodError only to be
>> confronted with another. I have used you cloneStyleFrom(HSSFCellStyle
>> source). However, when i open the spreadsheet in MS Excel it still
>> complains about having to many fonts.
>
> You'll still need to ensure you don't create too many cell styles,
> otherwise excel will still get in a miff.
>
> One option is to have a hashtable of old style to new style. If an entry
> doesn't exist in the hash, create one on the new wb and clone it over,
> then store the pair in the hash. Otherwise, look up the pre-existing new
> style for each old one, and use that
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/HSSFCellStyle-help-tp18401553p18484508.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]