阅读 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;
最佳答案
虽然添加 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/