Rounded corners of charts

Sep 10, 2012 at 7:09 AM

I couldn't find the option for rounded corners for charts (Format Chart Area > Border Styles > Rounded Corners) so I wrote the following property for the class ExcelChart:

        /// <summary>
        /// Is true if if the chart has rounded corners. Is null if rounded corners aren't specfied.
        /// </summary>
        public bool? HasRoundedCorners
        {
            get
            {
                var node = ChartXml.SelectSingleNode("c:chartSpace/c:roundedCorners", NameSpaceManager);
                if (node == null)
                    return null;
                return node.Attributes["val"].Value == "1";
            }
            set
            {
                var node = ChartXml.SelectSingleNode("c:chartSpace/c:roundedCorners", NameSpaceManager);
                if (node == null && value.HasValue)
                {
                    node = ChartXml.SelectSingleNode("c:chartSpace", NameSpaceManager);
                    var element = ChartXml.CreateNode(XmlNodeType.Element, "c", "roundedCorners", NameSpaceManager.LookupNamespace("c"));
                    var attribute = ChartXml.CreateAttribute("val");
                    if (value.Value)
                        attribute.Value = "1";
                    else
                        attribute.Value = "0";
                    element.Attributes.Append(attribute);
                    node.AppendChild(element);
                }
                else if (node != null && !value.HasValue)
                {
                    var chartSpace = ChartXml.SelectSingleNode("c:chartSpace", NameSpaceManager);
                    chartSpace.RemoveChild(node);
                }
                else if (node != null && value.HasValue)
                {
                    if (value.Value)
                        node.Attributes["val"].Value = "1";
                    else
                        node.Attributes["val"].Value = "0";
                }
                else
                {
                    // Value is null and no node exists so nothing should be done
                }
            }
        }
I'm not used to working with XML so I'm sure some things could be done in a better way. But if anyone else needs this feature this may at least give them somewhere to start.