在 EPPLUS ExcelChart 中关闭圆角

Turn off rounded corner in EPPLUS ExcelChart

正在阅读 Add RoundedCorners property to ExcelChart 我想 EPPLUS 默认会为 Excel 图表添加圆角。我喜欢去掉圆角并将 ExcelChart 保持在干净的方角中,但似乎无法在 EPPLUS 中找到这样做的方法(我可以在 Excel 本身中轻松切换).

我检查了每个 属性,并尝试了以下方法:

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; 

虽然添加 RoundedCorners 属性 的提交标记在版本 4.1.1 下,但实际上它似乎只包含在 4.5 beta 中。

来自 4.5.0.0 beta 1 发行说明:

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

我假设您使用的是稳定版本,它解释了为什么您看不到它。如果你想坚持当前的稳定版本,你可以同时通过直接修改xml来创建一个去除圆角的方法。

例如使用扩展方法:

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());
    }
}

然后应用到您的 ExcelChart

ec.ShowRoundedCorners(false);