【问题标题】:How to remove chart axis and lines using C# with interop library?如何使用 C# 和互操作库删除图表轴和线?
【发布时间】:2021-02-23 06:44:52
【问题描述】:

我有一个图表,其中包含一些数据。我不想显示 x 和 Y 轴。我以某种方式找到了如何删除图表中的图例。但未能隐藏轴。

我也只想删除网格线和轴。我有带有以下代码的图表对象。

  PowerPoint.Shape chartShape = slide.Shapes.AddChart(Microsoft.Office.Core.XlChartType.xlBarClustered, left, top, width, height);

  //Get the chart
  PowerPoint.Chart chart = chartShape.Chart;
  chart.Legend.Clear();

谁能知道如何用c#隐藏它?

【问题讨论】:

  • 在 Excel 中创建一个类似的图表,然后使用 Excel 的 VBA 宏记录器记录您手动进行所需更改时发生的情况。这通常会让您很好地了解如何以编程方式使用图表对象模型。
  • 我使用 c# 作为我的插件。这对我有帮助吗?
  • 我记录了它显示的细节ActiveChart.SetElement (msoElementPrimaryCategoryAxisNone),但我找不到在 c# VSTO 插件中使用它的方法。
  • 我不使用 C#,因此无法真正帮助从 VBA 进行翻译,但我想你会从 chart.SetElement ... 等开始
  • 谢谢。很有用的评论。您可以将其发布为答案吗? SetElement 的东西运行良好。

标签: c# powerpoint interop office-interop powerpoint-interop


【解决方案1】:

如果您使用Aspose.Slides for .NET而不是Office Interop,您将隐藏图表图例、轴和网格线,如下所示:

    using var presentation = new Presentation();
    var chart = presentation.Slides[0].Shapes.AddChart(ChartType.ClusteredBar, 20, 20, 400, 300);
    
    chart.HasLegend = false;
    
    chart.Axes.VerticalAxis.IsVisible = false;
    chart.Axes.HorizontalAxis.IsVisible = false;
    
    chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill;
    
    // Save the chart with default data
    presentation.Save("result.pptx", SaveFormat.Pptx);

默认数据的结果:

Documentation | API Reference | Free forum

您还可以评估 Aspose.Slides Cloud 以进行演示操作。这个基于 REST 的 API 允许您每月进行 150 次免费 API 调用,用于 API 学习和演示处理。

我在 Aspose 工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 2016-01-29
    相关资源
    最近更新 更多