internal void FromIconSet(X14.IconSet ics)
        {
            SetAllNull();

            if (ics.IconSetTypes != null)
            {
                IconSetType = ics.IconSetTypes.Value;
            }
            if (ics.ShowValue != null)
            {
                ShowValue = ics.ShowValue.Value;
            }
            if (ics.Percent != null)
            {
                Percent = ics.Percent.Value;
            }
            if (ics.Reverse != null)
            {
                Reverse = ics.Reverse.Value;
            }

            using (var oxr = OpenXmlReader.Create(ics))
            {
                SLConditionalFormattingValueObject2010 cfvo;
                SLConditionalFormattingIcon2010        cfi;
                while (oxr.Read())
                {
                    if (oxr.ElementType == typeof(X14.ConditionalFormattingValueObject))
                    {
                        cfvo = new SLConditionalFormattingValueObject2010();
                        cfvo.FromConditionalFormattingValueObject(
                            (X14.ConditionalFormattingValueObject)oxr.LoadCurrentElement());
                        Cfvos.Add(cfvo);
                    }
                    else if (oxr.ElementType == typeof(X14.ConditionalFormattingIcon))
                    {
                        cfi = new SLConditionalFormattingIcon2010();
                        cfi.FromConditionalFormattingIcon((X14.ConditionalFormattingIcon)oxr.LoadCurrentElement());
                        CustomIcons.Add(cfi);
                    }
                }
            }
        }
        internal X14.IconSet ToIconSet()
        {
            var ics = new X14.IconSet();

            if (IconSetType != X14.IconSetTypeValues.ThreeTrafficLights1)
            {
                ics.IconSetTypes = IconSetType;
            }
            if (!ShowValue)
            {
                ics.ShowValue = ShowValue;
            }
            if (!Percent)
            {
                ics.Percent = Percent;
            }
            if (Reverse)
            {
                ics.Reverse = Reverse;
            }
            if (CustomIcons.Count > 0)
            {
                ics.Custom = true;
            }

            foreach (var cfvo in Cfvos)
            {
                ics.Append(cfvo.ToConditionalFormattingValueObject());
            }

            foreach (var cfi in CustomIcons)
            {
                ics.Append(cfi.ToConditionalFormattingIcon());
            }

            return(ics);
        }
        internal X14.IconSet ToIconSet()
        {
            X14.IconSet ics = new X14.IconSet();
            if (this.IconSetType != X14.IconSetTypeValues.ThreeTrafficLights1)
            {
                ics.IconSetTypes = this.IconSetType;
            }
            if (!this.ShowValue)
            {
                ics.ShowValue = this.ShowValue;
            }
            if (!this.Percent)
            {
                ics.Percent = this.Percent;
            }
            if (this.Reverse)
            {
                ics.Reverse = this.Reverse;
            }
            if (this.CustomIcons.Count > 0)
            {
                ics.Custom = true;
            }

            foreach (SLConditionalFormattingValueObject2010 cfvo in this.Cfvos)
            {
                ics.Append(cfvo.ToConditionalFormattingValueObject());
            }

            foreach (SLConditionalFormattingIcon2010 cfi in this.CustomIcons)
            {
                ics.Append(cfi.ToConditionalFormattingIcon());
            }

            return(ics);
        }
Beispiel #4
0
        public override void WriteOpenXml(OpenXmlWriter writer)
        {
            X14.ConditionalFormatting cf = new X14.ConditionalFormatting();
            cf.AddNamespaceDeclaration("xm", "http://schemas.microsoft.com/office/excel/2006/main");
            ReferenceSequence referenceSequence = new ReferenceSequence();

            referenceSequence.Text = $"{SpreadsheetHelper.ExcelColumnFromNumber(RangeStart.ColumnIndex)}{RangeStart.RowIndex}:{SpreadsheetHelper.ExcelColumnFromNumber(RangeEnd.ColumnIndex)}{RangeEnd.RowIndex}";


            X14.ConditionalFormattingRule conditionalFormattingRule = new X14.ConditionalFormattingRule()
            {
                Type = ConditionalFormatValues.IconSet, Priority = 1, Id = Guid.NewGuid().ToString("B").ToUpper()
            };

            X14.IconSet iconSet1 = new X14.IconSet()
            {
                IconSetTypes = new EnumValue <IconSetTypeValues>(IconSetTypeValues.FourTrafficLights), ShowValue = false, Custom = true
            };
            //ConditionalFormattingIcon
            var conditionalFormattingIcon1 = new X14.ConditionalFormattingIcon()
            {
                IconSet = X14.IconSetTypeValues.NoIcons, IconId = (UInt32Value)0U
            };
            var conditionalFormattingIcon2 = new X14.ConditionalFormattingIcon()
            {
                IconSet = X14.IconSetTypeValues.ThreeSymbols2, IconId = (UInt32Value)2U
            };
            var conditionalFormattingIcon3 = new X14.ConditionalFormattingIcon()
            {
                IconSet = X14.IconSetTypeValues.ThreeSymbols, IconId = (UInt32Value)1U
            };
            var conditionalFormattingIcon4 = new X14.ConditionalFormattingIcon()
            {
                IconSet = X14.IconSetTypeValues.ThreeSymbols, IconId = (UInt32Value)0U
            };

            X14.ConditionalFormattingValueObject conditionalFormattingValueObject1 = new X14.ConditionalFormattingValueObject()
            {
                Type = X14.ConditionalFormattingValueObjectTypeValues.Numeric
            };
            Formula formula1 = new Formula();

            formula1.Text = "0";
            conditionalFormattingValueObject1.Append(formula1);

            X14.ConditionalFormattingValueObject conditionalFormattingValueObject2 = new X14.ConditionalFormattingValueObject()
            {
                Type = X14.ConditionalFormattingValueObjectTypeValues.Numeric
            };
            Formula formula2 = new Formula();

            formula2.Text = "1";
            conditionalFormattingValueObject2.Append(formula2);

            X14.ConditionalFormattingValueObject conditionalFormattingValueObject3 = new X14.ConditionalFormattingValueObject()
            {
                Type = X14.ConditionalFormattingValueObjectTypeValues.Numeric
            };
            Formula formula3 = new Formula();

            formula3.Text = "2";
            conditionalFormattingValueObject3.Append(formula3);

            X14.ConditionalFormattingValueObject conditionalFormattingValueObject4 = new X14.ConditionalFormattingValueObject()
            {
                Type = X14.ConditionalFormattingValueObjectTypeValues.Numeric
            };
            Formula formula4 = new Formula();

            formula4.Text = "3";
            conditionalFormattingValueObject4.Append(formula4);

            iconSet1.Append(
                conditionalFormattingValueObject1
                , conditionalFormattingValueObject2
                , conditionalFormattingValueObject3
                , conditionalFormattingValueObject4
                , conditionalFormattingIcon1
                , conditionalFormattingIcon2
                , conditionalFormattingIcon3
                , conditionalFormattingIcon4
                );

            conditionalFormattingRule.Append(iconSet1);
            cf.Append(conditionalFormattingRule);
            cf.Append(referenceSequence);
            writer.WriteElement(cf);
        }
        internal X14.IconSet ToIconSet()
        {
            X14.IconSet ics = new X14.IconSet();
            if (this.IconSetType != X14.IconSetTypeValues.ThreeTrafficLights1) ics.IconSetTypes = this.IconSetType;
            if (!this.ShowValue) ics.ShowValue = this.ShowValue;
            if (!this.Percent) ics.Percent = this.Percent;
            if (this.Reverse) ics.Reverse = this.Reverse;
            if (this.CustomIcons.Count > 0) ics.Custom = true;

            foreach (SLConditionalFormattingValueObject2010 cfvo in this.Cfvos)
            {
                ics.Append(cfvo.ToConditionalFormattingValueObject());
            }

            foreach (SLConditionalFormattingIcon2010 cfi in this.CustomIcons)
            {
                ics.Append(cfi.ToConditionalFormattingIcon());
            }

            return ics;
        }