Example #1
0
        private Fill CreateFill(string fillColor, PatternValues patternValue)
        {
            try
            {
                Fill        fill        = new Fill();
                PatternFill patternfill = new PatternFill();
                patternfill.PatternType = patternValue;
                if (!string.IsNullOrWhiteSpace(fillColor))
                {
                    patternfill.ForegroundColor = new ForegroundColor()
                    {
                        Rgb = new HexBinaryValue {
                            Value = fillColor
                        }
                    };
                }

                fill.PatternFill = patternfill;

                return(fill);
            }
            catch (Exception exception)
            {
                LogWriter.LogError("Unable to create Fill.");
                throw exception;
            }
        }
Example #2
0
        private uint GetFill(PatternType patternType, string backgroundColor)
        {
            PatternValues patternValue = GetFillStyle(patternType);

            //Check font type exists and return index
            uint fillIndex = 0;

            foreach (var fill in ActualFills.ChildElements.OfType <Fill>())
            {
                if (fill.PatternFill.PatternType == patternValue &&
                    (
                        string.IsNullOrEmpty(backgroundColor) ||
                        fill.PatternFill.ForegroundColor == null ||
                        fill.PatternFill.ForegroundColor.Rgb == backgroundColor
                    ))
                {
                    return(fillIndex);
                }
                fillIndex++;
            }

            //if not exists create new fill and append to actual fills
            SetFill(patternValue, backgroundColor);
            return(fillIndex);
        }
Example #3
0
        public MutableBooleanPattern Append(IEnumerable <bool> patternValues)
        {
            foreach (var value in patternValues)
            {
                PatternValues.Add(value);
            }

            return(this);
        }
Example #4
0
        public MutableBooleanPattern Append(int size, bool value)
        {
            PatternValues.Capacity += size;

            for (var i = 0; i < size; i++)
            {
                PatternValues.Add(value);
            }

            return(this);
        }
Example #5
0
        public MutableBooleanPattern Reset(IEnumerable <bool> patternValues)
        {
            PatternValues.Clear();

            foreach (var value in patternValues)
            {
                PatternValues.Add(value);
            }

            return(this);
        }
Example #6
0
 public void CreateStyle(string numberFormatCode,
                         double fontSize, string fontName, string fontColor
                         , bool fontBold, bool fontItalic, PatternValues fillPattern, string fillForeGroundColor, string borderLeftColor
                         , BorderStyleValues borderLeftStyleValue, string borderBottomColor, BorderStyleValues borderBottomStyleValue, string borderRightColor
                         , BorderStyleValues borderRightStyleValue, string borderTopColor, BorderStyleValues borderTopStyleValue, HorizontalAlignmentValues alignmentHorizontal, VerticalAlignmentValues alignmentVertical)
 {
     LCreateStyle(numberFormatCode,
                  fontSize, fontName, fontColor
                  , fontBold, fontItalic, fillPattern, fillForeGroundColor, borderLeftColor
                  , borderLeftStyleValue, borderBottomColor, borderBottomStyleValue, borderRightColor
                  , borderRightStyleValue, borderTopColor, borderTopStyleValue, alignmentHorizontal, alignmentVertical, textRotate);
 }
Example #7
0
        public MutableBooleanPattern Reset(int size, bool value)
        {
            PatternValues.Clear();
            PatternValues.Capacity = size;

            for (var i = 0; i < size; i++)
            {
                PatternValues.Add(value);
            }

            return(this);
        }
Example #8
0
        public override uint GetFillId(PatternValues pattern, DColor foreDColor, DColor backDColor)
        {
            var fillKey = OpenXMLExcels.GetFillStyleKey(pattern, foreDColor, backDColor);
            var fillId  = GetStyleId(fillKey);

            if (!fillId.HasValue)
            {
                var fill = OpenXMLExcels.GetFill(pattern, foreDColor, backDColor);
                fillId = _styleIdDic.Value[fillKey] = AddFills(fill);
            }

            return(fillId.Value);
        }
Example #9
0
        public MakeStyleIntent WithFill(string rgbColor, PatternValues patternType = PatternValues.Solid)
        {
            var _rgb        = rgbColor.TrimStart('#');
            var patternFill = new PatternFill()
            {
                PatternType = PatternValues.Solid
            };

            patternFill.ForegroundColor = new ForegroundColor()
            {
                Rgb = HexBinaryValue.FromString(_rgb)
            };
            return(WithFill(patternFill));
        }
Example #10
0
        private void SetFill(PatternValues patternValue, string backgroundColor = null)
        {
            Fill        fill        = new Fill();
            PatternFill patternFill = new PatternFill();

            patternFill.PatternType = new EnumValue <PatternValues>(patternValue);
            if (!string.IsNullOrEmpty(backgroundColor))
            {
                patternFill.ForegroundColor = new ForegroundColor {
                    Rgb = backgroundColor
                };
            }
            fill.PatternFill = patternFill;

            ActualFills.Append(fill);
            SetFillsCount();
        }
Example #11
0
        /// <summary>
        /// 获取填充
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="foreDColor"></param>
        /// <param name="backDColor"></param>
        public static Fill GetFill(PatternValues pattern, DColor foreDColor, DColor backDColor)
        {
            var fill = new Fill()
            {
                PatternFill = new PatternFill()
                {
                    PatternType = pattern,
                    //填充色
                    ForegroundColor = new ForegroundColor()
                    {
                        Rgb = HexBinaryValue.FromString(foreDColor.GetRgbString())
                    },
                    //暂时未知
                    BackgroundColor = new BackgroundColor()
                    {
                        Rgb = HexBinaryValue.FromString(backDColor.GetRgbString())
                    }
                }
            };

            return(fill);
        }
Example #12
0
 public static Fill CreateFill(Fills fills, PatternValues patternType)
 {
     var fill = new Fill();
     fill.Append(new PatternFill { PatternType = patternType });
     fills.Append(fill);
     return fill;
 }
Example #13
0
        /// <summary>
        /// Adds the fill to the stylesheet.
        /// </summary>
        /// <param name="stylesheet">The stylesheet.</param>
        /// <param name="foregroundColor">Color of the foreground.</param>
        /// <param name="patternValue">The pattern value.</param>
        /// <returns>The fill index.</returns>
        public static uint AddFill(this Stylesheet stylesheet, System.Windows.Media.Color foregroundColor, PatternValues patternValue)
        {
            Fill fill = new Fill();

            fill.PatternFill = new PatternFill()
            {
                ForegroundColor = new ForegroundColor()
                {
                    Rgb = new HexBinaryValue(TranslateColor(foregroundColor))
                },
                PatternType = new EnumValue <PatternValues>(patternValue),
            };
            stylesheet.Fills.Append(fill);
            stylesheet.Fills.Count = (uint)stylesheet.Fills.Count();
            uint fillId = (uint)stylesheet.Fills.ToList().IndexOf(fill);

            return(fillId);
        }
Example #14
0
 /// <summary>
 /// Set the pattern type, foreground color and background color of the fill pattern.
 /// </summary>
 /// <param name="PatternType">The pattern type. Default value is None.</param>
 /// <param name="ForegroundColorTheme">The theme color to be used for the foreground.</param>
 /// <param name="ForegroundColorTint">The tint applied to the foreground theme color, ranging from -1.0 to 1.0. Negative tints darken the theme color and positive tints lighten the theme color.</param>
 /// <param name="BackgroundColor">The color to be used for the background.</param>
 public void SetPatternFill(PatternValues PatternType, SLThemeColorIndexValues ForegroundColorTheme, double ForegroundColorTint, System.Drawing.Color BackgroundColor)
 {
     this.Fill.SetPattern(PatternType, ForegroundColorTheme, ForegroundColorTint, BackgroundColor);
 }
Example #15
0
 /// <summary>
 /// Set the pattern type, foreground color and background color of the fill pattern.
 /// </summary>
 /// <param name="PatternType">The pattern type. Default value is None.</param>
 /// <param name="ForegroundColor">The color to be used for the foreground.</param>
 /// <param name="BackgroundColorTheme">The theme color to be used for the background.</param>
 public void SetPatternFill(PatternValues PatternType, System.Drawing.Color ForegroundColor, SLThemeColorIndexValues BackgroundColorTheme)
 {
     this.Fill.SetPattern(PatternType, ForegroundColor, BackgroundColorTheme);
 }
Example #16
0
 private void SetAllNull()
 {
     this.clrForegroundColor = new SLColor(this.listThemeColors, this.listIndexedColors);
     HasForegroundColor = false;
     this.clrBackgroundColor = new SLColor(this.listThemeColors, this.listIndexedColors);
     HasBackgroundColor = false;
     this.vPatternType = PatternValues.None;
     HasPatternType = false;
 }
Example #17
0
 /// <summary>
 /// Set the pattern type, foreground color and background color of the fill pattern.
 /// </summary>
 /// <param name="PatternType">The pattern type. Default value is None.</param>
 /// <param name="ForegroundColorTheme">The theme color to be used for the foreground.</param>
 /// <param name="ForegroundColorTint">The tint applied to the foreground theme color, ranging from -1.0 to 1.0. Negative tints darken the theme color and positive tints lighten the theme color.</param>
 /// <param name="BackgroundColor">The color to be used for the background.</param>
 public void SetPattern(PatternValues PatternType, SLThemeColorIndexValues ForegroundColorTheme, double ForegroundColorTint, System.Drawing.Color BackgroundColor)
 {
     HasBeenAssignedValues = true;
     UsePatternFill = true;
     pfReal.PatternType = PatternType;
     pfReal.SetForegroundThemeColor(ForegroundColorTheme, ForegroundColorTint);
     pfReal.BackgroundColor = BackgroundColor;
 }
Example #18
0
 /// <summary>
 /// Set the pattern type, foreground color and background color of the fill pattern.
 /// </summary>
 /// <param name="PatternType">The pattern type. Default value is None.</param>
 /// <param name="ForegroundColor">The color to be used for the foreground.</param>
 /// <param name="BackgroundColor">The color to be used for the background.</param>
 public void SetPattern(PatternValues PatternType, System.Drawing.Color ForegroundColor, System.Drawing.Color BackgroundColor)
 {
     HasBeenAssignedValues = true;
     UsePatternFill = true;
     pfReal.PatternType = PatternType;
     pfReal.ForegroundColor = ForegroundColor;
     pfReal.BackgroundColor = BackgroundColor;
 }
        private static void ResolveFillWithPattern(Fills fills, PatternValues patternValues)
        {
            if (fills.Elements<Fill>().Any(f =>
                f.PatternFill.PatternType == patternValues
                && f.PatternFill.ForegroundColor == null
                && f.PatternFill.BackgroundColor == null
                )) return;

            var fill1 = new Fill();
            var patternFill1 = new PatternFill {PatternType = patternValues};
            fill1.AppendChild(patternFill1);
            fills.AppendChild(fill1);
        }
Example #20
0
        public MutableBooleanPattern Reset()
        {
            PatternValues.Clear();

            return(this);
        }
Example #21
0
 /// <summary>
 /// 获取Fill的Key
 /// </summary>
 /// <param name="pattern"></param>
 /// <param name="foreDColor"></param>
 /// <param name="backDColor"></param>
 /// <returns></returns>
 public static string GetFillStyleKey(PatternValues pattern, DColor?foreDColor, DColor?backDColor)
 => $"Fill.{pattern}.{foreDColor}.{backDColor}";
Example #22
0
        internal void FromFill(Fill f)
        {
            this.SetAllNull();

            bool bFound = false;
            if (f.PatternFill != null)
            {
                this.pfReal = new SLPatternFill(this.listThemeColors, this.listIndexedColors);
                this.pfReal.FromPatternFill(f.PatternFill);
                this.UsePatternFill = true;
                bFound = pfReal.HasForegroundColor || pfReal.HasBackgroundColor || pfReal.HasPatternType;
            }
            else if (f.GradientFill != null)
            {
                this.gfReal = new SLGradientFill(this.listThemeColors, this.listIndexedColors);
                this.gfReal.FromGradientFill(f.GradientFill);
                this.UsePatternFill = false;
                bFound = (gfReal.listGradientStops.Count > 0) || gfReal.HasType || gfReal.Degree != null || gfReal.Left != null || gfReal.Right != null || gfReal.Top != null || gfReal.Bottom != null;
            }

            if (bFound)
            {
                HasBeenAssignedValues = true;
            }
            else
            {
                HasBeenAssignedValues = false;

                // must have either PatternFill or GradientFill
                // Default will be an empty PatternFill
                this.pfReal = new SLPatternFill(this.listThemeColors, this.listIndexedColors);
                this.pfReal.PatternType = PatternValues.None;
                this.UsePatternFill = true;

                RemoveGradientFill();
            }
        }
Example #23
0
 /// <summary>
 /// Set the pattern type, foreground color and background color of the fill pattern.
 /// </summary>
 /// <param name="PatternType">The pattern type. Default value is None.</param>
 /// <param name="ForegroundColorTheme">The theme color to be used for the foreground.</param>
 /// <param name="ForegroundColorTint">The tint applied to the foreground theme color, ranging from -1.0 to 1.0. Negative tints darken the theme color and positive tints lighten the theme color.</param>
 /// <param name="BackgroundColorTheme">The theme color to be used for the background.</param>
 /// <param name="BackgroundColorTint">The tint applied to the background theme color, ranging from -1.0 to 1.0. Negative tints darken the theme color and positive tints lighten the theme color.</param>
 public void SetPatternFill(PatternValues PatternType, SLThemeColorIndexValues ForegroundColorTheme, double ForegroundColorTint, SLThemeColorIndexValues BackgroundColorTheme, double BackgroundColorTint)
 {
     this.Fill.SetPattern(PatternType, ForegroundColorTheme, ForegroundColorTint, BackgroundColorTheme, BackgroundColorTint);
 }
Example #24
0
 /// <summary>
 /// Set the pattern type.
 /// </summary>
 /// <param name="PatternType">The pattern type. Default value is None.</param>
 public void SetPatternType(PatternValues PatternType)
 {
     HasBeenAssignedValues = true;
     UsePatternFill = true;
     pfReal.PatternType = PatternType;
 }
Example #25
0
        private void LCreateStyle(string numberFormatCode,
                                  double fontSize, string fontName, System.Drawing.Color fontColor
                                  , bool fontBold, bool fontItalic, PatternValues fillPattern, System.Drawing.Color fillForeGroundColor, System.Drawing.Color borderLeftColor
                                  , BorderStyleValues borderLeftStyleValue, System.Drawing.Color borderBottomColor, BorderStyleValues borderBottomStyleValue, System.Drawing.Color borderRightColor
                                  , BorderStyleValues borderRightStyleValue, System.Drawing.Color borderTopColor, BorderStyleValues borderTopStyleValue, HorizontalAlignmentValues alignmentHorizontal, VerticalAlignmentValues alignmentVertical)
        {
            if (numberFormatCode != null)
            {
                NumberingFormat numberingFormat = new NumberingFormat();
                numberingFormat.FormatCode = numberFormatCode;
                _oNumberingFormat          = numberingFormat;
            }
            //font
            Font     font      = new Font();
            FontSize _fontSize = new FontSize()
            {
                Val = DoubleValue.FromDouble(fontSize)
            };

            font.Append(_fontSize);

            if (fontName != null)
            {
                FontName _fontName = new FontName()
                {
                    Val = fontName
                };
                font.Append(_fontName);
            }
            if (fontColor != null)
            {
                Color _fontColor = new Color()
                {
                    Rgb = new HexBinaryValue()
                    {
                        Value = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(fontColor.R, fontColor.G, fontColor.B)).Replace("#", "")
                    }
                };
                font.Append(_fontColor);
            }
            if (fontBold)
            {
                Bold _fontBold = new Bold();
                font.Append(_fontBold);
            }
            if (fontItalic)
            {
                Italic _fontItalic = new Italic();
                font.Append(_fontItalic);
            }
            _oFont = font;

            //fill
            Fill _fontFill = null;

            if (fillForeGroundColor == null)
            {
                _fontFill = new Fill(new PatternFill()
                {
                    PatternType = fillPattern
                });
            }
            else
            {
                _fontFill = new Fill(new PatternFill(
                                         new ForegroundColor()
                {
                    Rgb = new HexBinaryValue()
                    {
                        Value = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(fillForeGroundColor.R, fillForeGroundColor.G, fillForeGroundColor.B)).Replace("#", "")
                    }
                }
                                         )
                {
                    PatternType = PatternValues.Solid
                });
            }

            _oFill = _fontFill;

            //border
            Border     _border    = new Border();
            LeftBorder leftBorder = new LeftBorder()
            {
                Style = borderLeftStyleValue
            };

            Color colorLeftBorder = null;

            if (borderLeftColor != null)
            {
                colorLeftBorder = new Color()
                {
                    Rgb = new HexBinaryValue {
                        Value = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(borderLeftColor.R, borderLeftColor.G, borderLeftColor.B)).Replace("#", "")
                    }
                };
            }
            else
            {
                colorLeftBorder = new Color();
            }
            leftBorder.Append(colorLeftBorder);
            _border.Append(leftBorder);

            RightBorder rightBorder = new RightBorder()
            {
                Style = borderRightStyleValue
            };

            Color colorRightBorder = null;

            if (borderRightColor != null)
            {
                colorRightBorder = new Color()
                {
                    Rgb = new HexBinaryValue {
                        Value = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(borderRightColor.R, borderRightColor.G, borderRightColor.B)).Replace("#", "")
                    }
                };
            }
            else
            {
                colorRightBorder = new Color();
            }
            rightBorder.Append(colorRightBorder);
            _border.Append(rightBorder);

            TopBorder topBorder = new TopBorder()
            {
                Style = borderTopStyleValue
            };

            Color colorTopBorder = null;

            if (borderTopColor != null)
            {
                colorTopBorder = new Color()
                {
                    Rgb = new HexBinaryValue {
                        Value = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(borderTopColor.R, borderTopColor.G, borderTopColor.B)).Replace("#", "")
                    }
                };
            }
            else
            {
                colorTopBorder = new Color();
            }
            topBorder.Append(colorTopBorder);
            _border.Append(topBorder);

            BottomBorder bottomBorder = new BottomBorder()
            {
                Style = borderBottomStyleValue
            };

            Color colorBottomBorder = null;

            if (borderBottomColor != null)
            {
                colorBottomBorder = new Color()
                {
                    Rgb = new HexBinaryValue {
                        Value = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(borderBottomColor.R, borderBottomColor.G, borderBottomColor.B)).Replace("#", "")
                    }
                };
            }
            else
            {
                colorBottomBorder = new Color();
            }
            bottomBorder.Append(colorBottomBorder);
            _border.Append(bottomBorder);
            _oBorder = _border;

            Alignment _alignment = new Alignment();

            _alignment.Horizontal          = alignmentHorizontal;
            _alignment.Vertical            = alignmentVertical;
            _oAlignment                    = _alignment;
            _oAlignment.WrapText           = wrapText;
            _oAlignment.TextRotation.Value = textRotate;
        }
Example #26
0
 /// <summary>
 /// Set the pattern type, foreground color and background color of the fill pattern.
 /// </summary>
 /// <param name="PatternType">The pattern type. Default value is None.</param>
 /// <param name="ForegroundColor">The color to be used for the foreground.</param>
 /// <param name="BackgroundColorTheme">The theme color to be used for the background.</param>
 /// <param name="BackgroundColorTint">The tint applied to the background theme color, ranging from -1.0 to 1.0. Negative tints darken the theme color and positive tints lighten the theme color.</param>
 public void SetPattern(PatternValues PatternType, System.Drawing.Color ForegroundColor, SLThemeColorIndexValues BackgroundColorTheme, double BackgroundColorTint)
 {
     HasBeenAssignedValues = true;
     UsePatternFill = true;
     pfReal.PatternType = PatternType;
     pfReal.ForegroundColor = ForegroundColor;
     pfReal.SetBackgroundThemeColor(BackgroundColorTheme, BackgroundColorTint);
 }
Example #27
0
        public MutableBooleanPattern Append(bool value)
        {
            PatternValues.Add(value);

            return(this);
        }
Example #28
0
 /// <summary>
 /// Set the pattern type, foreground color and background color of the fill pattern.
 /// </summary>
 /// <param name="PatternType">The pattern type. Default value is None.</param>
 /// <param name="ForegroundColorTheme">The theme color to be used for the foreground.</param>
 /// <param name="ForegroundColorTint">The tint applied to the foreground theme color, ranging from -1.0 to 1.0. Negative tints darken the theme color and positive tints lighten the theme color.</param>
 /// <param name="BackgroundColorTheme">The theme color to be used for the background.</param>
 /// <param name="BackgroundColorTint">The tint applied to the background theme color, ranging from -1.0 to 1.0. Negative tints darken the theme color and positive tints lighten the theme color.</param>
 public void SetPattern(PatternValues PatternType, SLThemeColorIndexValues ForegroundColorTheme, double ForegroundColorTint, SLThemeColorIndexValues BackgroundColorTheme, double BackgroundColorTint)
 {
     HasBeenAssignedValues = true;
     UsePatternFill = true;
     pfReal.PatternType = PatternType;
     pfReal.SetForegroundThemeColor(ForegroundColorTheme, ForegroundColorTint);
     pfReal.SetBackgroundThemeColor(BackgroundColorTheme, BackgroundColorTint);
 }
Example #29
0
 /// <summary>
 /// 创建或获取填充Id
 /// </summary>
 /// <param name="pattern"></param>
 /// <param name="foreDColor"></param>
 /// <param name="backDColor"></param>
 /// <returns></returns>
 public abstract uint GetFillId(PatternValues pattern, DColor foreDColor, DColor backDColor);
Example #30
0
 /// <summary>
 /// Form SLPatternFill from DocumentFormat.OpenXml.Spreadsheet.PatternFill class.
 /// </summary>
 /// <param name="patternFill">The source PatternFill class.</param>
 public void FromPatternFill(PatternFill patternFill)
 {
     this.SetAllNull();
     if (patternFill.ForegroundColor != null)
     {
         this.clrForegroundColor.FromForegroundColor(patternFill.ForegroundColor);
         this.HasForegroundColor = !this.clrForegroundColor.IsEmpty();
     }
     if (patternFill.BackgroundColor != null)
     {
         this.clrBackgroundColor.FromBackgroundColor(patternFill.BackgroundColor);
         this.HasBackgroundColor = !this.clrBackgroundColor.IsEmpty();
     }
     if (patternFill.PatternType != null)
     {
         this.PatternType = patternFill.PatternType;
     }
 }
Example #31
0
 /// <summary>
 /// Set the pattern type, foreground color and background color of the fill pattern.
 /// </summary>
 /// <param name="PatternType">The pattern type. Default value is None.</param>
 /// <param name="ForegroundColor">The color to be used for the foreground.</param>
 /// <param name="BackgroundColor">The color to be used for the background.</param>
 public void SetPatternFill(PatternValues PatternType, System.Drawing.Color ForegroundColor, System.Drawing.Color BackgroundColor)
 {
     this.Fill.SetPattern(PatternType, ForegroundColor, BackgroundColor);
 }