PPT 主题颜色解释(Theme Color Scheme)

每个 PPTX 文件包含一个主题文件:

复制代码

ppt/theme/theme1.xml

其中定义了 12 种主题颜色:

名称 含义
bg1 Background 1
tx1 Text 1
bg2 Background 2
tx2 Text 2
accent1 强调色 1
accent2 强调色 2
accent3 强调色 3
accent4 强调色 4
accent5 强调色 5
accent6 强调色 6
hlink 超链接颜色
folHlink 访问过的超链接

accent6 就是 PPT 主题的第六个强调色。

不同模板 RGB 会不同。


🔍 如何获取 accent6 的 RGB 颜色?

Python-pptx 不支持直接取 theme 色的 RGB,需要解析 XML:

代码:读取主题颜色(精准版)

复制代码
复制代码
from pptx import Presentation
from lxml import etree

def get_theme_colors(ppt_path):
    prs = Presentation(ppt_path)
    theme_part = prs.part.theme.part
    xml = etree.fromstring(theme_part.blob)

    ns = {"a": "http://schemas.openxmlformats.org/drawingml/2006/main"}

    colors = {}
    scheme_clrs = xml.xpath("//a:themeElements/a:clrScheme/*", namespaces=ns)

    for clr in scheme_clrs:
        name = clr.tag.split("}")[-1]  # accent1, accent2...
        rgb = None

        srgbClr = clr.find("a:srgbClr", ns)
        if srgbClr is not None:
            rgb = srgbClr.get("val")

        colors[name] = rgb

    return colors

print(get_theme_colors("你的PPT路径.pptx"))

返回示例:

复制代码
复制代码
{
  'accent1': '4472C4',
  'accent6': '70AD47',
  'bg1': 'FFFFFF',
  ...
}
相关推荐
大模型RAG和Agent技术实践20 小时前
突破RAG边界:构建能“读懂“PPT逻辑与图文的智能问答系统实战(附完整源代码)
大模型·powerpoint·智能问答·rag
盘古工具20 小时前
PPT怎么放映?新手也能快速上手
powerpoint
取个鸣字真的难20 小时前
简单快速的用 Claude Code 帮你创建 PPT 生成 Skills
vscode·powerpoint·ai编程
GiantGo1 天前
一键导出PPT备注到Word
word·powerpoint·导出备注
kaka.liulin -study3 天前
EmberTrace AI | NoteBook Mode :DeepPPT Gen 智能PPT生成
人工智能·语言模型·powerpoint
小爷毛毛(卓寿杰)3 天前
SlideFlow: AI 驱动的 PPT 自动化生成引擎
人工智能·自动化·powerpoint·大语言模型
LAM LAB3 天前
【VBA/ppt】设置选中字体为红色
powerpoint·vba·wps
weixin_456907413 天前
使用 html为 ppt 文档添加文本像素格的实用方法
html·tensorflow·powerpoint
老兵发新帖3 天前
技术架构图drawio到PPT
powerpoint·draw.io
老兵发新帖4 天前
Markdown转PPT工具实践总结
powerpoint