internal void FromConditionalFormattingValueObject(X14.ConditionalFormattingValueObject cfvo)
        {
            this.SetAllNull();

            if (cfvo.Formula != null)
            {
                this.Formula = cfvo.Formula.Text;
            }
            this.Type = cfvo.Type.Value;
            if (cfvo.GreaterThanOrEqual != null)
            {
                this.GreaterThanOrEqual = cfvo.GreaterThanOrEqual.Value;
            }
        }
        internal X14.ConditionalFormattingValueObject ToConditionalFormattingValueObject()
        {
            X14.ConditionalFormattingValueObject cfvo = new X14.ConditionalFormattingValueObject();

            if (this.Formula.Length > 0)
            {
                if (this.Formula.StartsWith("="))
                {
                    cfvo.Formula = new Excel.Formula(this.Formula.Substring(1));
                }
                else
                {
                    cfvo.Formula = new Excel.Formula(this.Formula);
                }
            }
            cfvo.Type = this.Type;
            if (!this.GreaterThanOrEqual) cfvo.GreaterThanOrEqual = this.GreaterThanOrEqual;

            return cfvo;
        }
        internal X14.ConditionalFormattingValueObject ToConditionalFormattingValueObject()
        {
            X14.ConditionalFormattingValueObject cfvo = new X14.ConditionalFormattingValueObject();

            if (this.Formula.Length > 0)
            {
                if (this.Formula.StartsWith("="))
                {
                    cfvo.Formula = new Excel.Formula(this.Formula.Substring(1));
                }
                else
                {
                    cfvo.Formula = new Excel.Formula(this.Formula);
                }
            }
            cfvo.Type = this.Type;
            if (!this.GreaterThanOrEqual)
            {
                cfvo.GreaterThanOrEqual = this.GreaterThanOrEqual;
            }

            return(cfvo);
        }
Пример #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);
        }