MSO_CONNECT 未检测到。获取幻灯片上的行数?
MSO_CONNECT not being detected. Getting number of lines on a slide?
我需要获取幻灯片的行数。要访问这些行,我使用 MSO_CONNECTOR,因为它不是 AUTO_SHAPE。但是,当我 运行 下面的 returns 出于某种原因时 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
看来应该用MSO_CONNECTOR的属性来比较。
例如)
if shape.shape_type == MSO_CONNECTOR.STRAIGHT:
嗯,有意思。看起来我们离开了 Connector 对象的 .shape_type
属性。我会添加一个问题来解决这个问题。
与此同时,您可以检查有区别的 Connector
属性,例如 .begin_x
:
def is_connector(shape):
"""Return True if `shape` is a connector (line), False otherwise."""
return hasattr(shape, "begin_x")
我需要获取幻灯片的行数。要访问这些行,我使用 MSO_CONNECTOR,因为它不是 AUTO_SHAPE。但是,当我 运行 下面的 returns 出于某种原因时 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
看来应该用MSO_CONNECTOR的属性来比较。 例如)
if shape.shape_type == MSO_CONNECTOR.STRAIGHT:
嗯,有意思。看起来我们离开了 Connector 对象的 .shape_type
属性。我会添加一个问题来解决这个问题。
与此同时,您可以检查有区别的 Connector
属性,例如 .begin_x
:
def is_connector(shape):
"""Return True if `shape` is a connector (line), False otherwise."""
return hasattr(shape, "begin_x")