代码之家  ›  专栏  ›  技术社区  ›  Arie Livshin

当SmartArt位于占位符内时访问SmartArt形状(PowerPoint 2007)

  •  2
  • Arie Livshin  · 技术社区  · 16 年前

    我需要在PowerPoint2007中浏览每一种形状的智能艺术。 什么时候? shape.Type=msoSmartArt 然后我可以简单地浏览shape.groupitems中的形状。

    然而,何时 shape.Type == msoPlaceholder && shape.PlaceholderFormat.ContainedType==msoSmartArt 然后 shape.GroupItems 是空的。在这种情况下,如何访问智能艺术形状?


    我以前认为vba和c vsto基本相同。

    好吧-这里有区别。我在实际的vba中尝试了otaku的代码,它确实有效(对不起,otaku)。

    但是,我的程序是C VSTO,并且:

    foreach (Shape slideShape in pres.Slides[1].Shapes)
    {
      if (slideShape.Type != MsoShapeType.msoSmartArt &&   !(slideShape.Type == MsoShapeType.msoPlaceholder &&  slideShape.PlaceholderFormat.ContainedType==MsoShapeType.msoSmartArt))
     continue;
    
     GroupShapes shapes=slideShape.GroupItems;
     Debug.WriteLine(shapes.Count);
    }
    

    生产: shapes.Count=0 (当形状类型为占位符,而containedType为SmartArt时)。

    有什么想法吗?

    2 回复  |  直到 15 年前
        1
  •  3
  •   Todd Main    16 年前

    使用 GroupShapes ,像:

    Sub GetSAfromPlaceholder()
        Dim ap As Presentation: Set ap = ActivePresentation
        Dim sl As Slide: Set sl = ap.Slides(2)
        Dim sh As Shape: Set sh = sl.Shapes(2)
        Dim gsh As GroupShapes: Set gsh = sh.GroupItems
        If sh.Type = msoPlaceholder Then
            If sh.PlaceholderFormat.ContainedType = msoSmartArt Then
            Debug.Print "SmartArt Shape Count: " & gsh.Count
              For i = 1 To gsh.Count
                If gsh(i).TextFrame.HasText Then
                    Debug.Print gsh(i).TextFrame.TextRange.Text
                End If
                Next
            End If
        End If
    End Sub
    
        2
  •  0
  •   Arie Livshin    15 年前

    我使用的解决方法是复制并粘贴SmartArt。 粘贴的SmartArt现在在其GroupItem中具有所有形状。 处理完这些后,我删除粘贴的形状。