【问题标题】:PowerPoint Interop - How to access Chart out of a shape?PowerPoint Interop - 如何从形状中访问图表?
【发布时间】:2013-04-04 11:45:56
【问题描述】:

我正在使用办公自动化工具来处理 PowerPoint 文档,但在格式化图表时遇到了问题。

我正在使用以下程序集来格式化演示文稿 Microsoft.Office.Interop.PowerPoint 版本:12.0.0.0 Microsoft.Office.Interop.Graph 版本:12.0.0.0 要求是将一些样式(例如图例位置、颜色、字体等)应用于演示文稿中存在的图表。

我能够像这样验证形状 shape.HasChart == MsoTriState.msoTrue 但无法使图表对象脱离形状

尝试了以下代码,但收到 OLEFormat 异常 Graph.Chart 图表 = (Graph.Chart)shape.OLEFormat.Object

提前感谢您的帮助。

【问题讨论】:

    标签: charts interop powerpoint


    【解决方案1】:

    通过从 COM 选项卡中选择正确的引用解决了该问题。 来自线程的回答 - http://social.msdn.microsoft.com/Forums/en-US/officegeneral/thread/06cea2b7-f169-4f8a-b53e-4319b12b5450

    【讨论】:

      【解决方案2】:

      我知道您是从(相当).NET 的角度提出问题,但我会向您展示一些来自 VBA PowerPoint 的代码。我的目标是向您展示对象层次结构。我相信它对您解决问题很有帮助。

      Sub Chart_Elements()
      
      Dim CHRT As Chart
      'first shape in the 1st slide is chart
      Set CHRT = ActivePresentation.Slides(1).Shapes(1).Chart
      
      With CHRT
          'to set legend position
          .Legend.Position = xlLegendPositionBottom
          'to set size of 1st entry in legend
          .Legend.LegendEntries(1).Font.Size = 10
          'and so on
      End With
      End Sub
      

      如果该答案对您没有任何帮助,请考虑重新标记您的问题。

      【讨论】:

      • 感谢您的回复。正如我在帖子中提到的,我使用的是版本 12 的互操作程序集,其中我没有 Shape 的 Chart 属性。不支持 shape.Chart。
      • 通过从 COM 选项卡中选择正确的引用解决了该问题。来自线程的回答 - social.msdn.microsoft.com/Forums/en-US/officegeneral/thread/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多