PowerPoint Interop - 如何访问图表的形状?

时间:2013-04-04 11:45:56

标签: charts interop powerpoint

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

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

我能够验证形状     shape.HasChart == MsoTriState.msoTrue 但是无法使Chart对象脱离形状

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

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我知道你是从(相当).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

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

相关问题