【问题标题】:Can I change word font color using python?我可以使用 python 更改 word 字体颜色吗? 【发布时间】:2022-09-24 04:06:45 【问题描述】: 我正在使用 docxtpl 来处理 word 模板。 使用 RichText 可以更改新添加的字体,但我想更改 word 模板中存在的字体颜色。 有什么解决办法吗? 请提供足够的代码,以便其他人可以更好地理解或重现该问题。 标签: python docxtpl 【解决方案1】: 您可以将字体更改为您想要的颜色,直接更改为模板文档中的表达式。 因此,假设您要以颜色呈现的表达式为 {{website}},值为“堆栈溢出”,您可以在 Word 模板中设置表达式的字体: 并在您的代码中创建 context 和 render 它: template = DocxTemplate(path_to_template) context = {'website':"stack overflow"} template.render(context) template.save(path_to_output_file) 输出是彩色的: 【讨论】: