Example #1
0
        /// <summary>
        /// Gets the cell align attribute value for a specified align option
        /// </summary>
        /// <param name="align">The align option</param>
        /// <returns>The cell align attribute value</returns>
        public static string GetCellAlignAttributeValue(CellAlignOption align)
        {
            // Validate the arguments
            // align does not require validation


            string formattedValue = null;

            switch (align)
            {
            case CellAlignOption.Left:
                formattedValue = "left";
                break;

            case CellAlignOption.Center:
                formattedValue = "center";
                break;

            case CellAlignOption.Right:
                formattedValue = "right";
                break;

            default:
                throw new ArgumentException($"Argument {nameof(align)} contains an unsupported value.", nameof(align));
            }

            return(formattedValue);
        }
Example #2
0
        /// <summary>
        /// Adds a table cell element to the parent element
        /// </summary>
        /// <param name="parent">Reference to the parent element</param>
        /// <param name="root">Reference to the root XML document</param>
        /// <param name="content">The cell contents</param>
        /// <param name="align">The cell content alignment</param>
        public static void AddTableCellElement(XmlElement parent, XmlDocument root, string content, CellAlignOption align)
        {
            // Validate the arguments
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }
            // content does not require validation
            // align does not require validation


            // Add the cell element
            const string nodeName = "cell";
            XmlElement   node     = AddElement(parent, root, nodeName);

            node.InnerText = content;

            // Add the align attribute
            if (align != CellAlignOption.Left)
            {
                const string alignAttributeName = "align";
                string       alignValue         = GetCellAlignAttributeValue(align);
                AddAttribute(node, root, alignAttributeName, alignValue, false);
            }
        }