首页 > 解决方案 > 未检测到 MSO_CONNECT。获取幻灯片上的行数?

问题描述

我需要获取幻灯片上的行数。要访问这些行,我使用的是 MSO_CONNECTOR,因为它不是 AUTO_SHAPE。但是,当我运行以下命令时,由于某种原因,它会返回 None 值。我怎么知道一个形状是不是一条线?(尝试使用 is_connector 也返回错误)

def get_number_of_lines(slide):
    lines = 0
    for shape in slide.shapes:
        if shape.shape_type == MSO_CONNECTOR:
           print('it is a line')
           lines = lines + 1 

    return lines

标签: pythonpowerpointpython-pptx

解决方案


嗯,有趣。看起来我们离开.shape_type了 Connector 对象的属性。我会添加一个问题来解决这个问题。

同时,您可以检查一个独特的Connector属性,例如.begin_x

def is_connector(shape):
    """Return True if `shape` is a connector (line), False otherwise."""
    return hasattr(shape, "begin_x")

推荐阅读