コード例 #1
0
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context)
        {
            var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);

            var dataBar = new DataBar {
                ShowValue = !cf.ShowBarOnly
            };

            var conditionalFormatValueObject1 = GetConditionalFormatValueObjectByIndex(cf, 1, ConditionalFormatValueObjectValues.Min);
            var conditionalFormatValueObject2 = GetConditionalFormatValueObjectByIndex(cf, 2, ConditionalFormatValueObjectValues.Max);

            var color = new Color();

            switch (cf.Colors[1].ColorType)
            {
            case XLColorType.Color:
                color.Rgb = cf.Colors[1].Color.ToHex();
                break;

            case XLColorType.Theme:
                color.Theme = System.Convert.ToUInt32(cf.Colors[1].ThemeColor);
                break;

            case XLColorType.Indexed:
                color.Indexed = System.Convert.ToUInt32(cf.Colors[1].Indexed);
                break;
            }

            dataBar.Append(conditionalFormatValueObject1);
            dataBar.Append(conditionalFormatValueObject2);
            dataBar.Append(color);

            conditionalFormattingRule.Append(dataBar);

            var conditionalFormattingRuleExtensionList = new ConditionalFormattingRuleExtensionList();

            conditionalFormattingRuleExtensionList.Append(BuildRuleExtension(cf));
            conditionalFormattingRule.Append(conditionalFormattingRuleExtensionList);

            return(conditionalFormattingRule);
        }
コード例 #2
0
        internal ConditionalFormattingRule ToConditionalFormattingRule()
        {
            ConditionalFormattingRule cfr = new ConditionalFormattingRule();
            cfr.Type = this.Type;
            if (this.FormatId != null) cfr.FormatId = this.FormatId.Value;
            cfr.Priority = this.Priority;
            if (this.StopIfTrue) cfr.StopIfTrue = this.StopIfTrue;
            if (!this.AboveAverage) cfr.AboveAverage = this.AboveAverage;
            if (this.Percent) cfr.Percent = this.Percent;
            if (this.Bottom) cfr.Bottom = this.Bottom;
            if (HasOperator) cfr.Operator = this.Operator;
            if (this.Text != null && this.Text.Length > 0) cfr.Text = this.Text;
            if (HasTimePeriod) cfr.TimePeriod = this.TimePeriod;
            if (this.Rank != null) cfr.Rank = this.Rank.Value;
            if (this.StdDev != null) cfr.StdDev = this.StdDev.Value;
            if (this.EqualAverage) cfr.EqualAverage = this.EqualAverage;

            foreach (Formula f in this.Formulas)
            {
                cfr.Append((Formula)f.CloneNode(true));
            }
            if (HasColorScale) cfr.Append(this.ColorScale.ToColorScale());
            if (HasDataBar) cfr.Append(this.DataBar.ToDataBar());
            if (HasIconSet) cfr.Append(this.IconSet.ToIconSet());

            if (this.Extensions.Count > 0)
            {
                ConditionalFormattingRuleExtensionList extlist = new ConditionalFormattingRuleExtensionList();
                foreach (ConditionalFormattingRuleExtension ext in this.Extensions)
                {
                    extlist.Append((ConditionalFormattingRuleExtension)ext.CloneNode(true));
                }
                cfr.Append(extlist);
            }

            return cfr;
        }
コード例 #3
0
        internal ConditionalFormattingRule ToConditionalFormattingRule()
        {
            ConditionalFormattingRule cfr = new ConditionalFormattingRule();

            cfr.Type = this.Type;
            if (this.FormatId != null)
            {
                cfr.FormatId = this.FormatId.Value;
            }
            cfr.Priority = this.Priority;
            if (this.StopIfTrue)
            {
                cfr.StopIfTrue = this.StopIfTrue;
            }
            if (!this.AboveAverage)
            {
                cfr.AboveAverage = this.AboveAverage;
            }
            if (this.Percent)
            {
                cfr.Percent = this.Percent;
            }
            if (this.Bottom)
            {
                cfr.Bottom = this.Bottom;
            }
            if (HasOperator)
            {
                cfr.Operator = this.Operator;
            }
            if (this.Text != null && this.Text.Length > 0)
            {
                cfr.Text = this.Text;
            }
            if (HasTimePeriod)
            {
                cfr.TimePeriod = this.TimePeriod;
            }
            if (this.Rank != null)
            {
                cfr.Rank = this.Rank.Value;
            }
            if (this.StdDev != null)
            {
                cfr.StdDev = this.StdDev.Value;
            }
            if (this.EqualAverage)
            {
                cfr.EqualAverage = this.EqualAverage;
            }

            foreach (Formula f in this.Formulas)
            {
                cfr.Append((Formula)f.CloneNode(true));
            }
            if (HasColorScale)
            {
                cfr.Append(this.ColorScale.ToColorScale());
            }
            if (HasDataBar)
            {
                cfr.Append(this.DataBar.ToDataBar());
            }
            if (HasIconSet)
            {
                cfr.Append(this.IconSet.ToIconSet());
            }

            if (this.Extensions.Count > 0)
            {
                ConditionalFormattingRuleExtensionList extlist = new ConditionalFormattingRuleExtensionList();
                foreach (ConditionalFormattingRuleExtension ext in this.Extensions)
                {
                    extlist.Append((ConditionalFormattingRuleExtension)ext.CloneNode(true));
                }
                cfr.Append(extlist);
            }

            return(cfr);
        }
コード例 #4
0
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, Int32 priority, XLWorkbook.SaveContext context)
        {
            var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);

            var dataBar = new DataBar {
                ShowValue = !cf.ShowBarOnly
            };

            var conditionalFormatValueObject1 = new ConditionalFormatValueObject {
                Type = cf.ContentTypes[1].ToOpenXml()
            };

            if (cf.Values.Any() && cf.Values[1]?.Value != null)
            {
                conditionalFormatValueObject1.Val = cf.Values[1].Value;
            }

            var conditionalFormatValueObject2 = new ConditionalFormatValueObject {
                Type = cf.ContentTypes[2].ToOpenXml()
            };

            if (cf.Values.Count >= 2 && cf.Values[2]?.Value != null)
            {
                conditionalFormatValueObject2.Val = cf.Values[2].Value;
            }

            var color = new Color();

            switch (cf.Colors[1].ColorType)
            {
            case XLColorType.Color:
                color.Rgb = cf.Colors[1].Color.ToHex();
                break;

            case XLColorType.Theme:
                color.Theme = System.Convert.ToUInt32(cf.Colors[1].ThemeColor);
                break;

            case XLColorType.Indexed:
                color.Indexed = System.Convert.ToUInt32(cf.Colors[1].Indexed);
                break;
            }

            dataBar.Append(conditionalFormatValueObject1);
            dataBar.Append(conditionalFormatValueObject2);
            dataBar.Append(color);


            conditionalFormattingRule.Append(dataBar);

            if (cf.Colors.Count > 1)
            {
                ConditionalFormattingRuleExtensionList conditionalFormattingRuleExtensionList = new ConditionalFormattingRuleExtensionList();

                ConditionalFormattingRuleExtension conditionalFormattingRuleExtension = new ConditionalFormattingRuleExtension {
                    Uri = "{B025F937-C7B1-47D3-B67F-A62EFF666E3E}"
                };
                conditionalFormattingRuleExtension.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
                DocumentFormat.OpenXml.Office2010.Excel.Id id = new DocumentFormat.OpenXml.Office2010.Excel.Id
                {
                    Text = (cf as XLConditionalFormat).Id.WrapInBraces()
                };
                conditionalFormattingRuleExtension.Append(id);

                conditionalFormattingRuleExtensionList.Append(conditionalFormattingRuleExtension);

                conditionalFormattingRule.Append(conditionalFormattingRuleExtensionList);
            }
            return(conditionalFormattingRule);
        }
コード例 #5
0
        internal ConditionalFormattingRule ToConditionalFormattingRule()
        {
            var cfr = new ConditionalFormattingRule();

            cfr.Type = Type;
            if (FormatId != null)
            {
                cfr.FormatId = FormatId.Value;
            }
            cfr.Priority = Priority;
            if (StopIfTrue)
            {
                cfr.StopIfTrue = StopIfTrue;
            }
            if (!AboveAverage)
            {
                cfr.AboveAverage = AboveAverage;
            }
            if (Percent)
            {
                cfr.Percent = Percent;
            }
            if (Bottom)
            {
                cfr.Bottom = Bottom;
            }
            if (HasOperator)
            {
                cfr.Operator = Operator;
            }
            if ((Text != null) && (Text.Length > 0))
            {
                cfr.Text = Text;
            }
            if (HasTimePeriod)
            {
                cfr.TimePeriod = TimePeriod;
            }
            if (Rank != null)
            {
                cfr.Rank = Rank.Value;
            }
            if (StdDev != null)
            {
                cfr.StdDev = StdDev.Value;
            }
            if (EqualAverage)
            {
                cfr.EqualAverage = EqualAverage;
            }

            foreach (var f in Formulas)
            {
                cfr.Append((Formula)f.CloneNode(true));
            }
            if (HasColorScale)
            {
                cfr.Append(ColorScale.ToColorScale());
            }
            if (HasDataBar)
            {
                cfr.Append(DataBar.ToDataBar());
            }
            if (HasIconSet)
            {
                cfr.Append(IconSet.ToIconSet());
            }

            if (Extensions.Count > 0)
            {
                var extlist = new ConditionalFormattingRuleExtensionList();
                foreach (var ext in Extensions)
                {
                    extlist.Append((ConditionalFormattingRuleExtension)ext.CloneNode(true));
                }
                cfr.Append(extlist);
            }

            return(cfr);
        }