c# - 在 EPPLUS ExcelChart 中关闭圆角

标签 c# wpf epplus epplus-4

阅读 Add RoundedCorners property to 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

最佳答案

虽然添加 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);

关于c# - 在 EPPLUS ExcelChart 中关闭圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48161123/

相关文章:

c# - 可访问性不一致

c# - 在 WPF 应用程序中使用手写笔或手指按下触摸屏上的按钮时出现异常

wpf - 如何绑定(bind)到 TreeView 的子分支或叶子(MVVM 样式)?

c# - 弹出应用

c# - 使用 Linq 在 Epplus 工作表中选择分组的最大值和最小值

c# - 如何使用 EPplus 在 excel 中获取部分单元格样式?

c# - 使用 EPPlus 打开 Excel 文档

c# - HttpWebRequest resp.Headers ["Set-Cookie"] 为空

c# - 如何检查数组中的所有值是否相等

c# - 在 Xamarin 中将 cookie 放在 WebView 上