/** * Set the background fill color represented as a {@link XSSFColor} value. * <p> * For example: * <pre> * cs.SetFillPattern(XSSFCellStyle.FINE_DOTS ); * cs.SetFillBackgroundXSSFColor(new XSSFColor(java.awt.Color.RED)); * </pre> * optionally a Foreground and background fill can be applied: * <i>Note: Ensure Foreground color is set prior to background</i> * <pre> * cs.SetFillPattern(XSSFCellStyle.FINE_DOTS ); * cs.SetFillForegroundColor(new XSSFColor(java.awt.Color.BLUE)); * cs.SetFillBackgroundColor(new XSSFColor(java.awt.Color.GREEN)); * </pre> * or, for the special case of SOLID_FILL: * <pre> * cs.SetFillPattern(XSSFCellStyle.SOLID_FOREGROUND ); * cs.SetFillForegroundColor(new XSSFColor(java.awt.Color.GREEN)); * </pre> * It is necessary to set the fill style in order * for the color to be shown in the cell. * * @param color - the color to use */ public void SetFillBackgroundColor(XSSFColor color) { CT_Fill ct = GetCTFill(); CT_PatternFill ptrn = ct.GetPatternFill(); if (color == null) { if (ptrn != null) { ptrn.UnsetBgColor(); } } else { if (ptrn == null) { ptrn = ct.AddNewPatternFill(); } ptrn.bgColor = color.GetCTColor(); } int idx = _stylesSource.PutFill(new XSSFCellFill(ct)); _cellXf.fillId = (uint)idx; _cellXf.applyFill = (true); }
private void SetFillBackgroundColor(CT_Color color) { CT_PatternFill ptrn = _fill.IsSetPatternFill() ? _fill.patternFill : _fill.AddNewPatternFill(); if (color == null) { ptrn.UnsetBgColor(); } else { ptrn.bgColor = (color); } }