/**
         * 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);
        }
Exemple #2
0
        public void SetFillBackgroundColor(XSSFColor color)
        {
            CT_Fill        ctFill        = this.GetCTFill();
            CT_PatternFill ctPatternFill = ctFill.GetPatternFill();

            if (color == null)
            {
                ctPatternFill?.unsetBgColor();
            }
            else
            {
                if (ctPatternFill == null)
                {
                    ctPatternFill = ctFill.AddNewPatternFill();
                }
                ctPatternFill.bgColor = color.GetCTColor();
            }
            this._cellXf.fillId    = (uint)this._stylesSource.PutFill(new XSSFCellFill(ctFill));
            this._cellXf.applyFill = true;
        }