3

Reading Add RoundedCorners property to ExcelChart I guess EPPLUS adds rounded corner to ExcelChart by default. I like to get rid of the rounded corner and keep ExcelChart in clean squared corner, but can't seem to find a way to do so in EPPLUS (something that I can easily toggle in Excel itself).

I went through each property, and tried the following:

ExcelChart ec = ws.Drawings.AddChart("LineChart01", eChartType.LineMarkers);
ec.Title.Text = "LineChart01";
ec.Border.LineStyle = eLineStyle.Solid;
ec.Border.LineCap = eLineCap.Square;
ec.PlotArea.Border.LineCap = eLineCap.Square; 

EPPLUS Chart Rounded Corners

Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
KMC
  • 19,548
  • 58
  • 164
  • 253

1 Answers1

3

Although the commit for adding the RoundedCorners property is tagged under release 4.1.1, it is in fact only included from 4.5 beta it seems.

From the 4.5.0.0 beta 1 release notes :

4.5.0.0 Beta 1
...
* RoundedCorners property Add to ExcelChart

I am assuming you're using a stable version which explains why you don't see it. If you want to stick to a current stable version, you can in the meantime create a method to take out the rounded corners by modifying the xml directly.

For example using an extension method:

public static class ExcelChartExtensions
{
    /// <summary>
    /// Whether to show Rounded Corners or not for the border of the Excel Chart.
    /// </summary>
    public static void ShowRoundedCorners(this ExcelChart chart, bool show)
    {
        XmlElement roundedCornersElement = (XmlElement)chart.ChartXml.SelectSingleNode("c:chartSpace/c:roundedCorners", chart.WorkSheet.Drawings.NameSpaceManager);

        if (roundedCornersElement == null)
        {
            XmlElement chartSpaceElement = chart.ChartXml["c:chartSpace"];
            roundedCornersElement = chart.ChartXml.CreateElement("c:roundedCorners", chartSpaceElement.NamespaceURI);
            chartSpaceElement.AppendChild(roundedCornersElement);
        }

        roundedCornersElement.SetAttribute("val", Convert.ToInt32(show).ToString());
    }
}

and then apply to your ExcelChart

ec.ShowRoundedCorners(false);
singularhum
  • 5,072
  • 2
  • 24
  • 32