C
cosmo
hey there,
i have a big problem with those cellstyles. i want to add background
color to some cells, but apparently i just can "change" cell styles
from cells which already "have one".
for better understanding of my problem, here's the code:
for ( int i = 0; i <= rowcount; i++ ) {
for (int j = 0; j <= colcount; j++) {
HSSFRow row = s1.getRow((short)i);
if (row != null) {
HSSFCell cell = row.getCell((short)j);
if (cell != null) {
HSSFCellStyle style = cell.getCellStyle();
style.setFont(font);
style.setWrapText(true);
style.setFillForegroundColor(colorIndex);
if ( (j%4== 0) && (colorIndex ==
HSSFColor.LIGHT_CORNFLOWER_BLUE.index) ) {
colorIndex = HSSFColor.LEMON_CHIFFON.index;
}
else if ( (j%4== 0) && (colorIndex ==
HSSFColor.LEMON_CHIFFON.index) ) {
colorIndex =
HSSFColor.LIGHT_CORNFLOWER_BLUE.index;
}
}
}
}
}
}
this piece of code just works for cells, which already have attributes
in their cell styles like background color and border. cells which
just have a border and no color won't get the instructed color...
does anybody know what to do? is the method cell.getCellStyle() not
the best option in this case?
best regards and thx in advance,
manuela
i have a big problem with those cellstyles. i want to add background
color to some cells, but apparently i just can "change" cell styles
from cells which already "have one".
for better understanding of my problem, here's the code:
for ( int i = 0; i <= rowcount; i++ ) {
for (int j = 0; j <= colcount; j++) {
HSSFRow row = s1.getRow((short)i);
if (row != null) {
HSSFCell cell = row.getCell((short)j);
if (cell != null) {
HSSFCellStyle style = cell.getCellStyle();
style.setFont(font);
style.setWrapText(true);
style.setFillForegroundColor(colorIndex);
if ( (j%4== 0) && (colorIndex ==
HSSFColor.LIGHT_CORNFLOWER_BLUE.index) ) {
colorIndex = HSSFColor.LEMON_CHIFFON.index;
}
else if ( (j%4== 0) && (colorIndex ==
HSSFColor.LEMON_CHIFFON.index) ) {
colorIndex =
HSSFColor.LIGHT_CORNFLOWER_BLUE.index;
}
}
}
}
}
}
this piece of code just works for cells, which already have attributes
in their cell styles like background color and border. cells which
just have a border and no color won't get the instructed color...
does anybody know what to do? is the method cell.getCellStyle() not
the best option in this case?
best regards and thx in advance,
manuela