如何使用 python pptx 访问 mso autoshape 的类型?

How to access the type of mso autoshape using python pptx?

我知道如何添加某种类型的 auto_shape,例如 ISOSCELES_TRIANGLE。但是我们怎样才能找到幻灯片形状中的三角形呢?有没有办法访问 MsoAutoShapeType 并获取类型。我想计算一张幻灯片中有多少个三角形。谢谢

参考形状的 .auto_shape_type property, which returns one of the MsoAutoShapeType 值。

from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE

pres = Presentation("shapes.pptx")
slide = pres.slides[0]
triangles = []
for s in slide.shapes:
    try:
        if s.auto_shape_type == MSO_SHAPE.ISOSCELES_TRIANGLE:
            triangles.append(s)
    except AttributeError as e:
        # shape is **NOT** an auto_shape; ignore
        print(f'{s.name} is not an AutoShape')
        pass

print(len(triangles))