Reputation: 307
I'm copying a cellstyle from one cell to use it for many other rows:
HSSFCellStyle styleHdr = workbook.createCellStyle();
if ( styleHeader != null)
styleHdr.cloneStyleFrom(styleHeader);
String regexNumbers = "(^[0-9]+[.]{0,1}[0-9]*$)";
String regNatZahl = "(^[0-9]+$)";
CellStyle numericStyle = workbook.createCellStyle();
numericStyle.setDataFormat((short) 0);
HSSFFont font= workbook.createFont();
font.setBoldweight((short) 0);
styleHdr.setBorderLeft(CellStyle.BORDER_NONE);
styleHdr.setBorderRight(CellStyle.BORDER_NONE);
styleHdr.setBorderBottom(CellStyle.BORDER_THIN);
styleHdr.setBorderTop(CellStyle.BORDER_NONE);
styleHdr.setFont(font);
styleHdr.setFillBackgroundColor(new HSSFColor.WHITE().getIndex());
The styleHeader has as backgroundcolor grey, but
styleHdr.setFillBackgroundColor(new HSSFColor.WHITE().getIndex());
has no effect. Actually i want to delete the backgroundColor and not set it to White. Is this also possible?
Thx for your advises!
Upvotes: 0
Views: 4172
Reputation: 178243
It's a bit confusing when considering "background color" and "foreground color" in Apache POI, because there are two colors that can be applied to a cell background, styled with a pattern. In this case, the foreground color has been specified as gray and the fill pattern has been specified as "solid foreground". Other fill patterns use both colors.
In this case, if you want to avoid setting the background color to white, but you do want to remove the background color, then you need to set the fill pattern to "no fill" with setFillPattern
, using the CellStyle
constant NO_FILL
to specify that there should be no pattern applied. Then any foreground and background colors will be ignored.
styleHdr.setFillPattern(CellStyle.NO_FILL);
Also make sure that to apply the cell style to the desired cell(s) with setCellStyle
.
Upvotes: 7