Example #1
0
        internal SLDataBar Clone()
        {
            var db = new SLDataBar();

            db.Is2010                               = Is2010;
            db.MinimumType                          = MinimumType;
            db.MinimumValue                         = MinimumValue;
            db.MaximumType                          = MaximumType;
            db.MaximumValue                         = MaximumValue;
            db.Color                                = Color.Clone();
            db.BorderColor                          = BorderColor.Clone();
            db.NegativeFillColor                    = NegativeFillColor.Clone();
            db.NegativeBorderColor                  = NegativeBorderColor.Clone();
            db.AxisColor                            = AxisColor.Clone();
            db.MinLength                            = MinLength;
            db.MaxLength                            = MaxLength;
            db.ShowValue                            = ShowValue;
            db.Border                               = Border;
            db.Gradient                             = Gradient;
            db.Direction                            = Direction;
            db.NegativeBarColorSameAsPositive       = NegativeBarColorSameAsPositive;
            db.NegativeBarBorderColorSameAsPositive = NegativeBarBorderColorSameAsPositive;
            db.AxisPosition                         = AxisPosition;

            return(db);
        }
        internal SLDataBar2010 Clone()
        {
            var db = new SLDataBar2010();

            db.Cfvo1                                = Cfvo1.Clone();
            db.Cfvo2                                = Cfvo2.Clone();
            db.FillColor                            = FillColor.Clone();
            db.BorderColor                          = BorderColor.Clone();
            db.NegativeFillColor                    = NegativeFillColor.Clone();
            db.NegativeBorderColor                  = NegativeBorderColor.Clone();
            db.AxisColor                            = AxisColor.Clone();
            db.MinLength                            = MinLength;
            db.MaxLength                            = MaxLength;
            db.ShowValue                            = ShowValue;
            db.Border                               = Border;
            db.Gradient                             = Gradient;
            db.Direction                            = Direction;
            db.NegativeBarColorSameAsPositive       = NegativeBarColorSameAsPositive;
            db.NegativeBarBorderColorSameAsPositive = NegativeBarBorderColorSameAsPositive;
            db.AxisPosition                         = AxisPosition;

            return(db);
        }
Example #3
0
        internal SLDataBar2010 ToDataBar2010()
        {
            var db = new SLDataBar2010();

            switch (MinimumType)
            {
            case SLConditionalFormatAutoMinMaxValues.Automatic:
                db.Cfvo1.Type    = X14.ConditionalFormattingValueObjectTypeValues.AutoMin;
                db.Cfvo1.Formula = string.Empty;
                break;

            case SLConditionalFormatAutoMinMaxValues.Formula:
                db.Cfvo1.Type    = X14.ConditionalFormattingValueObjectTypeValues.Formula;
                db.Cfvo1.Formula = MinimumValue;
                break;

            case SLConditionalFormatAutoMinMaxValues.Number:
                db.Cfvo1.Type    = X14.ConditionalFormattingValueObjectTypeValues.Numeric;
                db.Cfvo1.Formula = MinimumValue;
                break;

            case SLConditionalFormatAutoMinMaxValues.Percent:
                db.Cfvo1.Type    = X14.ConditionalFormattingValueObjectTypeValues.Percent;
                db.Cfvo1.Formula = MinimumValue;
                break;

            case SLConditionalFormatAutoMinMaxValues.Percentile:
                db.Cfvo1.Type    = X14.ConditionalFormattingValueObjectTypeValues.Percentile;
                db.Cfvo1.Formula = MinimumValue;
                break;

            case SLConditionalFormatAutoMinMaxValues.Value:
                db.Cfvo1.Type    = X14.ConditionalFormattingValueObjectTypeValues.Min;
                db.Cfvo1.Formula = string.Empty;
                break;
            }

            switch (MaximumType)
            {
            case SLConditionalFormatAutoMinMaxValues.Automatic:
                db.Cfvo2.Type    = X14.ConditionalFormattingValueObjectTypeValues.AutoMax;
                db.Cfvo2.Formula = string.Empty;
                break;

            case SLConditionalFormatAutoMinMaxValues.Formula:
                db.Cfvo2.Type    = X14.ConditionalFormattingValueObjectTypeValues.Formula;
                db.Cfvo2.Formula = MaximumValue;
                break;

            case SLConditionalFormatAutoMinMaxValues.Number:
                db.Cfvo2.Type    = X14.ConditionalFormattingValueObjectTypeValues.Numeric;
                db.Cfvo2.Formula = MaximumValue;
                break;

            case SLConditionalFormatAutoMinMaxValues.Percent:
                db.Cfvo2.Type    = X14.ConditionalFormattingValueObjectTypeValues.Percent;
                db.Cfvo2.Formula = MaximumValue;
                break;

            case SLConditionalFormatAutoMinMaxValues.Percentile:
                db.Cfvo2.Type    = X14.ConditionalFormattingValueObjectTypeValues.Percentile;
                db.Cfvo2.Formula = MaximumValue;
                break;

            case SLConditionalFormatAutoMinMaxValues.Value:
                db.Cfvo2.Type    = X14.ConditionalFormattingValueObjectTypeValues.Max;
                db.Cfvo2.Formula = string.Empty;
                break;
            }

            db.FillColor           = Color.Clone();
            db.BorderColor         = BorderColor.Clone();
            db.NegativeFillColor   = NegativeFillColor.Clone();
            db.NegativeBorderColor = NegativeBorderColor.Clone();
            db.AxisColor           = AxisColor.Clone();
            db.MinLength           = MinLength;
            db.MaxLength           = MaxLength;
            db.ShowValue           = ShowValue;
            db.Border    = Border;
            db.Gradient  = Gradient;
            db.Direction = Direction;
            db.NegativeBarColorSameAsPositive       = NegativeBarColorSameAsPositive;
            db.NegativeBarBorderColorSameAsPositive = NegativeBarBorderColorSameAsPositive;
            db.AxisPosition = AxisPosition;

            return(db);
        }
        internal void FromDataBar(X14.DataBar db)
        {
            SetAllNull();

            using (var oxr = OpenXmlReader.Create(db))
            {
                var i = 0;
                while (oxr.Read())
                {
                    if (oxr.ElementType == typeof(X14.ConditionalFormattingValueObject))
                    {
                        if (i == 0)
                        {
                            Cfvo1.FromConditionalFormattingValueObject(
                                (X14.ConditionalFormattingValueObject)oxr.LoadCurrentElement());
                            ++i;
                        }
                        else if (i == 1)
                        {
                            Cfvo2.FromConditionalFormattingValueObject(
                                (X14.ConditionalFormattingValueObject)oxr.LoadCurrentElement());
                            ++i;
                        }
                    }
                    else if (oxr.ElementType == typeof(X14.FillColor))
                    {
                        FillColor.FromFillColor((X14.FillColor)oxr.LoadCurrentElement());
                    }
                    else if (oxr.ElementType == typeof(X14.BorderColor))
                    {
                        BorderColor.FromBorderColor((X14.BorderColor)oxr.LoadCurrentElement());
                    }
                    else if (oxr.ElementType == typeof(X14.NegativeFillColor))
                    {
                        NegativeFillColor.FromNegativeFillColor((X14.NegativeFillColor)oxr.LoadCurrentElement());
                    }
                    else if (oxr.ElementType == typeof(X14.NegativeBorderColor))
                    {
                        NegativeBorderColor.FromNegativeBorderColor((X14.NegativeBorderColor)oxr.LoadCurrentElement());
                    }
                    else if (oxr.ElementType == typeof(X14.BarAxisColor))
                    {
                        AxisColor.FromBarAxisColor((X14.BarAxisColor)oxr.LoadCurrentElement());
                    }
                }
            }

            if (db.MinLength != null)
            {
                MinLength = db.MinLength.Value;
            }
            if (db.MaxLength != null)
            {
                MaxLength = db.MaxLength.Value;
            }
            if (db.ShowValue != null)
            {
                ShowValue = db.ShowValue.Value;
            }
            if (db.Border != null)
            {
                Border = db.Border.Value;
            }
            if (db.Gradient != null)
            {
                Gradient = db.Gradient.Value;
            }
            if (db.Direction != null)
            {
                Direction = db.Direction.Value;
            }
            if (db.NegativeBarColorSameAsPositive != null)
            {
                NegativeBarColorSameAsPositive = db.NegativeBarColorSameAsPositive.Value;
            }
            if (db.NegativeBarBorderColorSameAsPositive != null)
            {
                NegativeBarBorderColorSameAsPositive = db.NegativeBarBorderColorSameAsPositive.Value;
            }
            if (db.AxisPosition != null)
            {
                AxisPosition = db.AxisPosition.Value;
            }
        }
        internal X14.DataBar ToDataBar(bool RenderFillColor)
        {
            var db = new X14.DataBar();

            if (MinLength != 10)
            {
                db.MinLength = MinLength;
            }

            // according to Open XML specs, this cannot be more than 100 percent.
            if (MaxLength > 100)
            {
                MaxLength = 100;
            }
            if (MaxLength != 90)
            {
                db.MaxLength = MaxLength;
            }

            if (!ShowValue)
            {
                db.ShowValue = ShowValue;
            }
            if (Border)
            {
                db.Border = Border;
            }
            if (!Gradient)
            {
                db.Gradient = Gradient;
            }
            if (Direction != X14.DataBarDirectionValues.Context)
            {
                db.Direction = Direction;
            }
            if (NegativeBarColorSameAsPositive)
            {
                db.NegativeBarColorSameAsPositive = NegativeBarColorSameAsPositive;
            }
            if (!NegativeBarBorderColorSameAsPositive)
            {
                db.NegativeBarBorderColorSameAsPositive = NegativeBarBorderColorSameAsPositive;
            }
            if (AxisPosition != X14.DataBarAxisPositionValues.Automatic)
            {
                db.AxisPosition = AxisPosition;
            }

            db.Append(Cfvo1.ToConditionalFormattingValueObject());
            db.Append(Cfvo2.ToConditionalFormattingValueObject());

            // The condition is mainly if the priority of the parent rule exists. See Open XML specs.
            if (RenderFillColor)
            {
                db.Append(FillColor.ToFillColor());
            }

            if (Border)
            {
                db.Append(BorderColor.ToBorderColor());
            }
            if (!NegativeBarColorSameAsPositive)
            {
                db.Append(NegativeFillColor.ToNegativeFillColor());
            }
            if (!NegativeBarBorderColorSameAsPositive && Border)
            {
                db.Append(NegativeBorderColor.ToNegativeBorderColor());
            }
            if (AxisPosition != X14.DataBarAxisPositionValues.None)
            {
                db.Append(AxisColor.ToBarAxisColor());
            }

            return(db);
        }