Exemplo n.º 1
0
        public static OpenXml.ForegroundColor MapToForegroundColor(this Color color)
        {
            var fc = new OpenXml.ForegroundColor();

            MapColor(fc, color);
            return(fc);
        }
        private static Fill GetNewFill(FillInfo fillInfo, Boolean ignoreMod = true)
        {
            var fill = new Fill();

            var patternFill = new PatternFill();
            if (fillInfo.Fill.PatternTypeModified || ignoreMod)
                patternFill.PatternType = fillInfo.Fill.PatternType.ToOpenXml();

            if (fillInfo.Fill.PatternColorModified || ignoreMod)
            {
                var foregroundColor = new ForegroundColor();
                if (fillInfo.Fill.PatternColor.ColorType == XLColorType.Color)
                    foregroundColor.Rgb = fillInfo.Fill.PatternColor.Color.ToHex();
                else if (fillInfo.Fill.PatternColor.ColorType == XLColorType.Indexed)
                    foregroundColor.Indexed = (UInt32)fillInfo.Fill.PatternColor.Indexed;
                else
                {
                    foregroundColor.Theme = (UInt32)fillInfo.Fill.PatternColor.ThemeColor;
                    if (fillInfo.Fill.PatternColor.ThemeTint != 1)
                        foregroundColor.Tint = fillInfo.Fill.PatternColor.ThemeTint;
                }
                patternFill.AppendChild(foregroundColor);
            }

            if (fillInfo.Fill.PatternBackgroundColorModified || ignoreMod)
            {
                var backgroundColor = new BackgroundColor();
                if (fillInfo.Fill.PatternBackgroundColor.ColorType == XLColorType.Color)
                    backgroundColor.Rgb = fillInfo.Fill.PatternBackgroundColor.Color.ToHex();
                else if (fillInfo.Fill.PatternBackgroundColor.ColorType == XLColorType.Indexed)
                    backgroundColor.Indexed = (UInt32)fillInfo.Fill.PatternBackgroundColor.Indexed;
                else
                {
                    backgroundColor.Theme = (UInt32)fillInfo.Fill.PatternBackgroundColor.ThemeColor;
                    if (fillInfo.Fill.PatternBackgroundColor.ThemeTint != 1)
                        backgroundColor.Tint = fillInfo.Fill.PatternBackgroundColor.ThemeTint;
                }
                patternFill.AppendChild(backgroundColor);
            }

            fill.AppendChild(patternFill);

            return fill;
        }