/// <summary>
        /// Create the 'cfvo'/'color' nodes in the right order. They should appear like this:
        ///		"cfvo"   --> Low Value (value object)
        ///		"cfvo"   --> Middle Value (value object)
        ///		"cfvo"   --> High Value (value object)
        ///		"color"  --> Low Value (color)
        ///		"color"  --> Middle Value (color)
        ///		"color"  --> High Value (color)
        /// </summary>
        /// <param name="nodeType"></param>
        /// <param name="attributePath"></param>
        /// <param name="attributeValue"></param>
        private void CreateNodeByOrdem(
            eExcelConditionalFormattingValueObjectNodeType nodeType,
            string attributePath,
            string attributeValue)
        {
            // Save the current TopNode
            XmlNode currentTopNode = TopNode;

            string           nodePath        = ExcelConditionalFormattingValueObjectType.GetNodePathByNodeType(nodeType);
            int              nodeOrder       = GetNodeOrder();
            eNodeInsertOrder nodeInsertOrder = eNodeInsertOrder.SchemaOrder;
            XmlNode          referenceNode   = null;

            if (nodeOrder > 1)
            {
                // Find the node just before the one we need to include
                referenceNode = TopNode.SelectSingleNode(
                    string.Format(
                        "{0}[position()={1}]",
                        // {0}
                        nodePath,
                        // {1}
                        nodeOrder - 1),
                    _worksheet.NameSpaceManager);

                // Only if the prepend node exists than insert after
                if (referenceNode != null)
                {
                    nodeInsertOrder = eNodeInsertOrder.After;
                }
            }

            // Create the node in the right order
            var node = CreateComplexNode(
                TopNode,
                string.Format(
                    "{0}[position()={1}]",
                    // {0}
                    nodePath,
                    // {1}
                    nodeOrder),
                nodeInsertOrder,
                referenceNode);

            // Point to the new node as the temporary TopNode (we need it for the XmlHelper functions)
            TopNode = node;

            // Add/Remove the attribute (if the attributeValue is empty then it will be removed)
            SetXmlNodeString(
                node,
                attributePath,
                attributeValue,
                true);

            // Point back to the <cfvo>/<color> parent node
            TopNode = currentTopNode;
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nodeType"></param>
        /// <returns></returns>
        public static string GetNodePathByNodeType(
            eExcelConditionalFormattingValueObjectNodeType nodeType)
        {
            switch (nodeType)
            {
            case eExcelConditionalFormattingValueObjectNodeType.Cfvo:
                return(ExcelConditionalFormattingConstants.Paths.Cfvo);

            case eExcelConditionalFormattingValueObjectNodeType.Color:
                return(ExcelConditionalFormattingConstants.Paths.Color);
            }

            return(string.Empty);
        }
		/// <summary>
		/// Create the 'cfvo'/'color' nodes in the right order. They should appear like this:
		///		"cfvo"   --> Low Value (value object)
		///		"cfvo"   --> Middle Value (value object)
		///		"cfvo"   --> High Value (value object)
		///		"color"  --> Low Value (color)
		///		"color"  --> Middle Value (color)
		///		"color"  --> High Value (color)
		/// </summary>
		/// <param name="nodeType"></param>
		/// <param name="attributePath"></param>
		/// <param name="attributeValue"></param>
		private void CreateNodeByOrdem(
			eExcelConditionalFormattingValueObjectNodeType nodeType,
			string attributePath,
			string attributeValue)
		{
      // Save the current TopNode
      XmlNode currentTopNode = TopNode;

      string nodePath = ExcelConditionalFormattingValueObjectType.GetNodePathByNodeType(nodeType);
			int nodeOrder = GetNodeOrder();
			eNodeInsertOrder nodeInsertOrder = eNodeInsertOrder.SchemaOrder;
			XmlNode referenceNode = null;

			if (nodeOrder > 1)
			{
				// Find the node just before the one we need to include
				referenceNode = TopNode.SelectSingleNode(
					string.Format(
						"{0}[position()={1}]",
					// {0}
						nodePath,
					// {1}
						nodeOrder - 1),
					_worksheet.NameSpaceManager);

				// Only if the prepend node exists than insert after
				if (referenceNode != null)
				{
					nodeInsertOrder = eNodeInsertOrder.After;
				}
			}

			// Create the node in the right order
			var node = CreateComplexNode(
				TopNode,
				string.Format(
					"{0}[position()={1}]",
				// {0}
					nodePath,
				// {1}
					nodeOrder),
				nodeInsertOrder,
				referenceNode);

      // Point to the new node as the temporary TopNode (we need it for the XmlHelper functions)
      TopNode = node;

      // Add/Remove the attribute (if the attributeValue is empty then it will be removed)
      SetXmlNodeString(
        node,
        attributePath,
        attributeValue,
        true);

      // Point back to the <cfvo>/<color> parent node
      TopNode = currentTopNode;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="nodeType"></param>
		/// <returns></returns>
		public static string GetNodePathByNodeType(
			eExcelConditionalFormattingValueObjectNodeType nodeType)
		{
			switch(nodeType)
			{
				case eExcelConditionalFormattingValueObjectNodeType.Cfvo:
					return ExcelConditionalFormattingConstants.Paths.Cfvo;

				case eExcelConditionalFormattingValueObjectNodeType.Color:
					return ExcelConditionalFormattingConstants.Paths.Color;
			}

			return string.Empty;
		}