读取矩形/texbox的轮廓颜色

2024-10-04 05:20:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图读取一个矩形的轮廓颜色,我得到以下错误

AttributeError:没有颜色类型“\u NoneColor”的.rgb属性

我在不同的幻灯片中使用相同的代码,结果正如预期的那样。我肯定有一些不正确的形状,但是,我不能准确地确定问题。。。有人能帮忙吗?你知道吗

对于幻灯片3中的形状。形状:

if shape.name[:9] == 'Rectangle':

    shape_color = shape.fill.fore_color.rgb
    line_color = shape.line.color.rgb

Tags: 代码类型属性颜色错误linergbcolor
1条回答
网友
1楼 · 发布于 2024-10-04 05:20:55

颜色类型和填充类型有很多可能的组合。你需要从一开始就开始,一路走下去,一边询问类型。你知道吗

from pptx.enum.dml import MSO_COLOR_TYPE, MSO_FILL

def read_outline_color(shape):
    line_fill = shape.line.fill
    print("fill-type == %s" % line_fill.type)
    #  -we only handle solid, which is most common
    #  -the other common value is "background" which means no-fill
    if line_fill.type != MSO_FILL.SOLID:
        return

    #  -color can be specified as specific RGB color or a theme color
    #  -like ACCENT_1
    line_color = line_fill.fore_color
    print("color-type == %s" % line_color.type)
    if line_color.type == MSO_COLOR_TYPE.SCHEME:
        print("color == %s" % line_color.theme_color
    elif line_color.type == MSO_COLOR_TYPE.RGB:
        print("color == %s" % line_color.rgb
    else:
        print("No line color")

相关问题 更多 >