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

            var colorScale = new ColorScale();

            for (Int32 i = 1; i <= cf.ContentTypes.Count; i++)
            {
                var type = cf.ContentTypes[i].ToOpenXml();
                var val  = (cf.Values.ContainsKey(i) && cf.Values[i] != null) ? cf.Values[i].Value : null;

                var conditionalFormatValueObject = new ConditionalFormatValueObject {
                    Type = type
                };
                if (val != null)
                {
                    conditionalFormatValueObject.Val = val;
                }

                colorScale.Append(conditionalFormatValueObject);
            }

            for (Int32 i = 1; i <= cf.Colors.Count; i++)
            {
                Color color = new Color {
                    Rgb = cf.Colors[i].Color.ToHex()
                };
                colorScale.Append(color);
            }

            conditionalFormattingRule.Append(colorScale);

            return(conditionalFormattingRule);
        }
コード例 #2
0
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context)
        {
            String val = GetQuoted(cf.Values[1]);

            var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);
            var cfStyle = (cf.Style as XLStyle).Value;

            if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue))
            {
                conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key];
            }

            conditionalFormattingRule.Operator = cf.Operator.ToOpenXml();

            var formula = new Formula(val);

            conditionalFormattingRule.Append(formula);

            if (cf.Operator == XLCFOperator.Between || cf.Operator == XLCFOperator.NotBetween)
            {
                var formula2 = new Formula {
                    Text = GetQuoted(cf.Values[2])
                };
                conditionalFormattingRule.Append(formula2);
            }

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

            conditionalFormattingRule.FormatId = (uint)context.DifferentialFormats[cf.Style];
            return(conditionalFormattingRule);
        }
コード例 #4
0
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context)
        {
            String val = GetQuoted(cf.Values[1]);

            var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);

            conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style];
            conditionalFormattingRule.Operator = cf.Operator.ToOpenXml();

            var formula = new Formula();

            if (cf.Operator == XLCFOperator.Equal || cf.Operator == XLCFOperator.NotEqual)
            {
                formula.Text = val;
            }
            else
            {
                formula.Text = val;
            }
            conditionalFormattingRule.Append(formula);

            if (cf.Operator == XLCFOperator.Between || cf.Operator == XLCFOperator.NotBetween)
            {
                var formula2 = new Formula {
                    Text = GetQuoted(cf.Values[2])
                };
                conditionalFormattingRule.Append(formula2);
            }

            return(conditionalFormattingRule);
        }
コード例 #5
0
ファイル: XLCFTopConverter.cs プロジェクト: zxcvas/ClosedXML
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context)
        {
            UInt32 val = UInt32.Parse(cf.Values[1].Value);
            var    conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);

            conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style];
            conditionalFormattingRule.Percent  = cf.Percent;
            conditionalFormattingRule.Rank     = val;
            conditionalFormattingRule.Bottom   = cf.Bottom;
            return(conditionalFormattingRule);
        }
コード例 #6
0
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context)
        {
            var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);

            if (!cf.Style.Equals(XLWorkbook.DefaultStyle))
            {
                conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style];
            }

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

            conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style];

            var formula = new Formula {
                Text = "LEN(TRIM(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "))>0"
            };

            conditionalFormattingRule.Append(formula);

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

            var colorScale = new ColorScale();

            for (Int32 i = 1; i <= cf.ContentTypes.Count; i++)
            {
                var type = cf.ContentTypes[i].ToOpenXml();
                var val  = cf.Values.TryGetValue(i, out XLFormula formula) ? formula?.Value : null;

                var conditionalFormatValueObject = new ConditionalFormatValueObject {
                    Type = type
                };
                if (val != null)
                {
                    conditionalFormatValueObject.Val = val;
                }

                colorScale.Append(conditionalFormatValueObject);
            }

            for (Int32 i = 1; i <= cf.Colors.Count; i++)
            {
                var xlColor = cf.Colors[i];
                var color   = new Color();
                switch (xlColor.ColorType)
                {
                case XLColorType.Color:
                    color.Rgb = xlColor.Color.ToHex();
                    break;

                case XLColorType.Theme:
                    color.Theme = System.Convert.ToUInt32(xlColor.ThemeColor);
                    break;

                case XLColorType.Indexed:
                    color.Indexed = System.Convert.ToUInt32(xlColor.Indexed);
                    break;
                }

                colorScale.Append(color);
            }

            conditionalFormattingRule.Append(colorScale);

            return(conditionalFormattingRule);
        }
コード例 #9
0
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context)
        {
            UInt32 val = UInt32.Parse(cf.Values[1].Value);
            var    conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);
            var    cfStyle = (cf.Style as XLStyle).Value;

            if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue))
            {
                conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key];
            }

            conditionalFormattingRule.Percent = cf.Percent;
            conditionalFormattingRule.Rank    = val;
            conditionalFormattingRule.Bottom  = cf.Bottom;
            return(conditionalFormattingRule);
        }
コード例 #10
0
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context)
        {
            String val = cf.Values[1].Value;
            var    conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);

            conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style];
            conditionalFormattingRule.Operator = ConditionalFormattingOperatorValues.ContainsText;
            conditionalFormattingRule.Text     = val;

            var formula = new Formula {
                Text = "NOT(ISERROR(SEARCH(\"" + val + "\"," + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + ")))"
            };

            conditionalFormattingRule.Append(formula);

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

            if (!cf.Style.Equals(XLWorkbook.DefaultStyle))
            {
                conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style];
            }

            var formula = new Formula {
                Text = "NOT(ISERROR(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "))"
            };

            conditionalFormattingRule.Append(formula);

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

            var iconSet = new IconSet {
                ShowValue = !cf.ShowIconOnly, Reverse = cf.ReverseIconOrder, IconSetValue = cf.IconSetStyle.ToOpenXml()
            };
            Int32 count = cf.Values.Count;

            for (Int32 i = 1; i <= count; i++)
            {
                var conditionalFormatValueObject = new ConditionalFormatValueObject {
                    Type = cf.ContentTypes[i].ToOpenXml(), Val = cf.Values[i].Value, GreaterThanOrEqual = cf.IconSetOperators[i] == XLCFIconSetOperator.EqualOrGreaterThan
                };
                iconSet.Append(conditionalFormatValueObject);
            }
            conditionalFormattingRule.Append(iconSet);
            return(conditionalFormattingRule);
        }
コード例 #13
0
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context)
        {
            var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);

            if (!cf.Style.Equals(XLWorkbook.DefaultStyle))
            {
                conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style];
            }

            conditionalFormattingRule.TimePeriod = cf.TimePeriod.ToOpenXml();

            var address = cf.Range.RangeAddress.FirstAddress.ToStringRelative(false);
            var formula = new Formula {
                Text = String.Format(formulaTemplates[cf.TimePeriod], address)
            };

            conditionalFormattingRule.Append(formula);

            return(conditionalFormattingRule);
        }
コード例 #14
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);
        }
コード例 #15
0
        public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context)
        {
            String val = cf.Values[1].Value;
            var    conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority);

            if (!cf.Style.Equals(XLWorkbook.DefaultStyle))
            {
                conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cf.Style];
            }

            conditionalFormattingRule.Operator = ConditionalFormattingOperatorValues.EndsWith;
            conditionalFormattingRule.Text     = val;

            var formula = new Formula {
                Text = "RIGHT(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "," + val.Length.ToString() + ")=\"" + val + "\""
            };

            conditionalFormattingRule.Append(formula);

            return(conditionalFormattingRule);
        }
コード例 #16
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);
        }