从PPT表格中提取填充颜色信息

问题描述 投票:0回答:1

在 PowerPoint 演示文稿中,我有一个表格,其中一列填充了不同的颜色。是否可以自动识别/提取每个单元格中填充的 RGB 值或颜色?

尝试了 pptx 库,但无法提取填充颜色信息。

colors powerpoint extract fill python-pptx
1个回答
0
投票

鉴于

PowerPointExample.pptx
在第一张幻灯片上有一个表格作为第一个形状,并且某些单元格具有纯色填充颜色,那么以下应该可以获取填充颜色:

但是单元格也可以通过表格样式着色。并且 python.pptx 不支持获取该内容。

from pptx import Presentation
from pptx.enum.dml import MSO_FILL

presentation = Presentation('./PowerPointExample.pptx')
slide = presentation.slides[0]
table = slide.shapes[0].table
for cell in table.iter_cells():
    fill_format = cell.fill
    if fill_format.type == MSO_FILL.SOLID:
        fore_color = fill_format.fore_color
        print(fore_color.rgb)
© www.soinside.com 2019 - 2024. All rights reserved.