EPPLUS ExcelChart如何关闭圆角?

3
阅读添加RoundedCorners属性到ExcelChart,我猜EPPLUS默认会给ExcelChart添加圆角。我想要去掉圆角并将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; 

EPPLUS Chart Rounded Corners

1个回答

3
尽管添加“RoundedCorners”属性的提交标签在4.1.1版本下,但事实上它似乎只包含在4.5 beta中。
来自4.5.0.0 beta 1发行说明:
4.5.0.0 Beta 1
...
* 添加ExcelChart的RoundedCorners属性
我假设您正在使用稳定版本,这就解释了为什么您看不到它。如果您想坚持使用当前的稳定版本,同时可以通过修改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());
    }
}

然后应用于您的Excel图表中

ec.ShowRoundedCorners(false);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接