/****************************************************************************************/

        #region Private Properties

        #endregion Private Properties

        /****************************************************************************************/

        #region Constructors
        /// <summary>
        ///
        /// </summary>
        /// <param name="priority"></param>
        /// <param name="address"></param>
        /// <param name="worksheet"></param>
        /// <param name="itemElementNode"></param>
        /// <param name="namespaceManager"></param>
        internal ExcelConditionalFormattingFourIconSet(
            ExcelAddress address,
            int priority,
            ExcelWorksheet worksheet,
            XmlNode itemElementNode,
            XmlNamespaceManager namespaceManager)
            : base(
                eExcelConditionalFormattingRuleType.FourIconSet,
                address,
                priority,
                worksheet,
                itemElementNode,
                (namespaceManager == null) ? worksheet.NameSpaceManager : namespaceManager)
        {
            if (itemElementNode != null && itemElementNode.HasChildNodes)
            {
                XmlNode iconNode4 = TopNode.SelectSingleNode("d:iconSet/d:cfvo[position()=4]", NameSpaceManager);
                Icon4 = new ExcelConditionalFormattingIconDataBarValue(
                    eExcelConditionalFormattingRuleType.FourIconSet,
                    address,
                    worksheet,
                    iconNode4,
                    namespaceManager);
            }
            else
            {
                XmlNode iconSetNode = TopNode.SelectSingleNode("d:iconSet", NameSpaceManager);
                var     iconNode4   = iconSetNode.OwnerDocument.CreateElement(ExcelConditionalFormattingConstants.Paths.Cfvo, ExcelPackage.schemaMain);
                iconSetNode.AppendChild(iconNode4);


                Icon4 = new ExcelConditionalFormattingIconDataBarValue(eExcelConditionalFormattingValueObjectType.Percent,
                                                                       75,
                                                                       "",
                                                                       eExcelConditionalFormattingRuleType.ThreeIconSet,
                                                                       address,
                                                                       priority,
                                                                       worksheet,
                                                                       iconNode4,
                                                                       namespaceManager);
            }
        }
        /****************************************************************************************/

        #region Private Properties

        #endregion Private Properties

        /****************************************************************************************/

        #region Constructors
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="address"></param>
        /// <param name="priority"></param>
        /// <param name="worksheet"></param>
        /// <param name="itemElementNode"></param>
        /// <param name="namespaceManager"></param>
        internal ExcelConditionalFormattingIconSetBase(
            eExcelConditionalFormattingRuleType type,
            ExcelAddress address,
            int priority,
            ExcelWorksheet worksheet,
            XmlNode itemElementNode,
            XmlNamespaceManager namespaceManager)
            : base(
                type,
                address,
                priority,
                worksheet,
                itemElementNode,
                (namespaceManager == null) ? worksheet.NameSpaceManager : namespaceManager)
        {
            if (itemElementNode != null && itemElementNode.HasChildNodes)
            {
                int pos = 1;
                foreach (XmlNode node in itemElementNode.SelectNodes("d:iconSet/d:cfvo", NameSpaceManager))
                {
                    if (pos == 1)
                    {
                        Icon1 = new ExcelConditionalFormattingIconDataBarValue(
                            type,
                            address,
                            worksheet,
                            node,
                            namespaceManager);
                    }
                    else if (pos == 2)
                    {
                        Icon2 = new ExcelConditionalFormattingIconDataBarValue(
                            type,
                            address,
                            worksheet,
                            node,
                            namespaceManager);
                    }
                    else if (pos == 3)
                    {
                        Icon3 = new ExcelConditionalFormattingIconDataBarValue(
                            type,
                            address,
                            worksheet,
                            node,
                            namespaceManager);
                    }
                    else
                    {
                        break;
                    }
                    pos++;
                }
            }
            else
            {
                var iconSetNode = CreateComplexNode(
                    Node,
                    ExcelConditionalFormattingConstants.Paths.IconSet);

                //Create the <iconSet> node inside the <cfRule> node
                double spann;
                if (type == eExcelConditionalFormattingRuleType.ThreeIconSet)
                {
                    spann = 3;
                }
                else if (type == eExcelConditionalFormattingRuleType.FourIconSet)
                {
                    spann = 4;
                }
                else
                {
                    spann = 5;
                }

                var iconNode1 = iconSetNode.OwnerDocument.CreateElement(ExcelConditionalFormattingConstants.Paths.Cfvo, ExcelPackage.schemaMain);
                iconSetNode.AppendChild(iconNode1);
                Icon1 = new ExcelConditionalFormattingIconDataBarValue(eExcelConditionalFormattingValueObjectType.Percent,
                                                                       0,
                                                                       "",
                                                                       eExcelConditionalFormattingRuleType.ThreeIconSet,
                                                                       address,
                                                                       priority,
                                                                       worksheet,
                                                                       iconNode1,
                                                                       namespaceManager);

                var iconNode2 = iconSetNode.OwnerDocument.CreateElement(ExcelConditionalFormattingConstants.Paths.Cfvo, ExcelPackage.schemaMain);
                iconSetNode.AppendChild(iconNode2);
                Icon2 = new ExcelConditionalFormattingIconDataBarValue(eExcelConditionalFormattingValueObjectType.Percent,
                                                                       Math.Round(100D / spann, 0),
                                                                       "",
                                                                       eExcelConditionalFormattingRuleType.ThreeIconSet,
                                                                       address,
                                                                       priority,
                                                                       worksheet,
                                                                       iconNode2,
                                                                       namespaceManager);

                var iconNode3 = iconSetNode.OwnerDocument.CreateElement(ExcelConditionalFormattingConstants.Paths.Cfvo, ExcelPackage.schemaMain);
                iconSetNode.AppendChild(iconNode3);
                Icon3 = new ExcelConditionalFormattingIconDataBarValue(eExcelConditionalFormattingValueObjectType.Percent,
                                                                       Math.Round(100D * (2D / spann), 0),
                                                                       "",
                                                                       eExcelConditionalFormattingRuleType.ThreeIconSet,
                                                                       address,
                                                                       priority,
                                                                       worksheet,
                                                                       iconNode3,
                                                                       namespaceManager);
                Type = type;
            }
        }
Exemplo n.º 3
0
        /****************************************************************************************/

        #region Private Properties

        #endregion Private Properties

        /****************************************************************************************/

        #region Constructors
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="priority"></param>
        /// <param name="address"></param>
        /// <param name="worksheet"></param>
        /// <param name="itemElementNode"></param>
        /// <param name="namespaceManager"></param>
        internal ExcelConditionalFormattingDataBar(
            eExcelConditionalFormattingRuleType type,
            ExcelAddress address,
            int priority,
            ExcelWorksheet worksheet,
            XmlNode itemElementNode,
            XmlNamespaceManager namespaceManager)
            : base(
                type,
                address,
                priority,
                worksheet,
                itemElementNode,
                (namespaceManager == null) ? worksheet.NameSpaceManager : namespaceManager)
        {
            SchemaNodeOrder = new string[] { "cfvo", "color" };
            //Create the <dataBar> node inside the <cfRule> node
            if (itemElementNode != null && itemElementNode.HasChildNodes)
            {
                bool high = false;
                foreach (XmlNode node in itemElementNode.SelectNodes("d:dataBar/d:cfvo", NameSpaceManager))
                {
                    if (high == false)
                    {
                        LowValue = new ExcelConditionalFormattingIconDataBarValue(
                            type,
                            address,
                            worksheet,
                            node,
                            namespaceManager);
                        high = true;
                    }
                    else
                    {
                        HighValue = new ExcelConditionalFormattingIconDataBarValue(
                            type,
                            address,
                            worksheet,
                            node,
                            namespaceManager);
                    }
                }
            }
            else
            {
                var iconSetNode = CreateComplexNode(
                    Node,
                    ExcelConditionalFormattingConstants.Paths.DataBar);

                var lowNode = iconSetNode.OwnerDocument.CreateElement(ExcelConditionalFormattingConstants.Paths.Cfvo, ExcelPackage.schemaMain);
                iconSetNode.AppendChild(lowNode);
                LowValue = new ExcelConditionalFormattingIconDataBarValue(eExcelConditionalFormattingValueObjectType.Min,
                                                                          0,
                                                                          "",
                                                                          eExcelConditionalFormattingRuleType.DataBar,
                                                                          address,
                                                                          priority,
                                                                          worksheet,
                                                                          lowNode,
                                                                          namespaceManager);

                var highNode = iconSetNode.OwnerDocument.CreateElement(ExcelConditionalFormattingConstants.Paths.Cfvo, ExcelPackage.schemaMain);
                iconSetNode.AppendChild(highNode);
                HighValue = new ExcelConditionalFormattingIconDataBarValue(eExcelConditionalFormattingValueObjectType.Max,
                                                                           0,
                                                                           "",
                                                                           eExcelConditionalFormattingRuleType.DataBar,
                                                                           address,
                                                                           priority,
                                                                           worksheet,
                                                                           highNode,
                                                                           namespaceManager);
            }
            Type = type;
        }