Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获得powerpoint演示文稿中的所有形状?(我需要使用OpenXml)_C#_Vsto_Powerpoint_Office Interop - Fatal编程技术网

C# 如何获得powerpoint演示文稿中的所有形状?(我需要使用OpenXml)

C# 如何获得powerpoint演示文稿中的所有形状?(我需要使用OpenXml),c#,vsto,powerpoint,office-interop,C#,Vsto,Powerpoint,Office Interop,我需要从所有幻灯片中获取活动演示文稿中的所有形状,包括C#中分组项目中的形状 我需要在列表或数组中返回所有形状(形状) 您可以通过属性枚举幻灯片的形状。类似地,您可以通过属性枚举子形状(仅适用于msoGroupshape type)。总而言之: public static IEnumerable<Shape> EnumerateShapes(Presentation presentation) { return presentation.Slides.Cast<Slid

我需要从所有幻灯片中获取活动演示文稿中的所有形状,包括C#中分组项目中的形状

我需要在列表或数组中返回所有形状(形状)


您可以通过属性枚举幻灯片的形状。类似地,您可以通过属性枚举子形状(仅适用于
msoGroup
shape type)。总而言之:

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;
        }
    }
}
公共静态IEnumerable枚举形状(演示文稿)
{
返回presentation.Slides.Cast()。选择多个(幻灯片=>
枚举形状(slide.Shapes.Cast());
}
公共静态IEnumerable枚举形状(IEnumerable形状)
{
foreach(形状中的形状)
{
屈服-回归曲线;
if(shape.Type==Microsoft.Office.Core.MsoShapeType.msoGroup)
{
foreach(枚举形状中的var subShape(shape.GroupItems.Cast())
收益子形;
}
}
}
请注意,这种递归是有代价的,将上述方法转换为递归可能是明智的