答案 0 :(得分:1)
您可以通过Shapes
属性枚举幻灯片的形状。同样,您可以通过GroupItems
属性枚举子形状(仅适用于msoGroup
形状类型)。放在一起:
public static IEnumerable<Shape> EnumerateShapes(Presentation presentation)
{
return presentation.Slides.Cast<Slide>().SelectMany(slide =>
EnumerateShapes(slide.Shapes.Cast<Shape>()));
}
public static IEnumerable<Shape> EnumerateShapes(IEnumerable<Shape> shapes)
{
foreach (Shape shape in shapes)
{
yield return shape;
if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoGroup)
{
foreach (var subShape in EnumerateShapes(shape.GroupItems.Cast<Shape>()))
yield return subShape;
}
}
}
请注意,这种递归是有代价的,将上述方法转换为non-recursive one也许是明智的。