【问题标题】:Remove Gridlines in LineChart in Excel using C#.net (Microsoft.Office.Interop.Excel)使用 C#.net (Microsoft.Office.Interop.Excel) 在 Excel 中删除 LineChart 中的网格线
【发布时间】:2017-01-12 09:19:52
【问题描述】:

我在使用 C#.Net MVC 和 DLL (Microsoft.Office.Interop.Excel) 在 Excel 中删除/隐藏 LINE CHART 中的网格线时遇到问题我想删除它或只是隐藏它,因为这是客户的需要。我看过很多文章,但它仍然不适合我。

Please click here for my sample excel

图像中的 3 个数字是我要删除或隐藏的内容。

这是我的 Border、ChartArea 和 PlotArea 透明度代码。

  //Plot Area          
            chartPage.PlotArea.Format.Fill.Solid();
            chartPage.PlotArea.Format.Fill.ForeColor.RGB = (int)XlRgbColor.rgbWhite;
            chartPage.PlotArea.Format.Fill.Transparency = (float)1;
  //Chart Area
            chartPage.ChartArea.Format.Fill.Solid();
            chartPage.ChartArea.Format.Fill.ForeColor.RGB = (int)XlRgbColor.rgbWhite;
            chartPage.ChartArea.Format.Fill.Transparency = (float)1;
  //Border
            chartPage.ChartArea.Format.Line.ForeColor.RGB = (int)XlRgbColor.rgbWhite;
            chartPage.ChartArea.Format.Line.Transparency = (float)1;

我的问题是网格线,请参考图片。

任何帮助将不胜感激。

谢谢!

【问题讨论】:

  • 选择那些对象并选择线条颜色为白色。如果您不想要背景网格,请选择所有单元格并将背景选择为白色。
  • 我已经用我的 ChartArea 和 PlotArea 做到了这一点,并将其设置为透明。因此,对于网格,它也必须是透明的,或者只是将其删除。如果您可以提供示例代码,那就太好了。 :)

标签: c# .net asp.net-mvc excel linechart


【解决方案1】:

我已经找到了解决这个问题的方法。

我希望这对所有遇到同样问题的人有所帮助。

//This will get the X-Axis (#3 in the image)
Axis xAxis = (Axis)chartPage.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary);

//This will get the Y-Axis (#2 in the image)
Axis yAxis = (Axis)chartPage.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);

//This will delete the Grid Lines (#1 in the image)        
xAxis.MajorGridlines.Delete();
//This will delete the X-Axis (#3 in the image)
xAxis.Delete();
//This will delete the Y-Axis (#2 in the image)
yAxis.Delete();

干杯!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多