private void SetAllNull()
        {
            Formulas      = new List <Formula>();
            ColorScale    = new SLColorScale();
            HasColorScale = false;
            DataBar       = new SLDataBar();
            HasDataBar    = false;
            IconSet       = new SLIconSet();
            HasIconSet    = false;

            Extensions = new List <ConditionalFormattingRuleExtension>();

            Type = ConditionalFormatValues.DataBar;

            DifferentialFormat    = new SLDifferentialFormat();
            HasDifferentialFormat = false;

            FormatId      = null;
            Priority      = 1;
            StopIfTrue    = false;
            AboveAverage  = true;
            Percent       = false;
            Bottom        = false;
            Operator      = ConditionalFormattingOperatorValues.Equal;
            HasOperator   = false;
            Text          = null;
            TimePeriod    = TimePeriodValues.Today;
            HasTimePeriod = false;
            Rank          = null;
            StdDev        = null;
            EqualAverage  = false;
        }
        internal SLColorScale Clone()
        {
            var cs = new SLColorScale();

            int i;

            cs.Cfvos = new List <SLConditionalFormatValueObject>();
            for (i = 0; i < Cfvos.Count; ++i)
            {
                cs.Cfvos.Add(Cfvos[i].Clone());
            }

            cs.Colors = new List <SLColor>();
            for (i = 0; i < Colors.Count; ++i)
            {
                cs.Colors.Add(Colors[i].Clone());
            }

            return(cs);
        }
        internal void FromConditionalFormattingRule(ConditionalFormattingRule cfr)
        {
            SetAllNull();

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

            using (var oxr = OpenXmlReader.Create(cfr))
            {
                while (oxr.Read())
                {
                    if (oxr.ElementType == typeof(Formula))
                    {
                        Formulas.Add((Formula)oxr.LoadCurrentElement().CloneNode(true));
                    }
                    else if (oxr.ElementType == typeof(ColorScale))
                    {
                        ColorScale = new SLColorScale();
                        ColorScale.FromColorScale((ColorScale)oxr.LoadCurrentElement());
                        HasColorScale = true;
                    }
                    else if (oxr.ElementType == typeof(DataBar))
                    {
                        DataBar = new SLDataBar();
                        DataBar.FromDataBar((DataBar)oxr.LoadCurrentElement());
                        HasDataBar = true;
                    }
                    else if (oxr.ElementType == typeof(IconSet))
                    {
                        IconSet = new SLIconSet();
                        IconSet.FromIconSet((IconSet)oxr.LoadCurrentElement());
                        HasIconSet = true;
                    }
                    else if (oxr.ElementType == typeof(ConditionalFormattingRuleExtension))
                    {
                        Extensions.Add((ConditionalFormattingRuleExtension)oxr.LoadCurrentElement().CloneNode(true));
                    }
                }
            }
        }