【问题标题】:How to change text color in python-pptx?如何更改 python-pptx 中的文本颜色?
【发布时间】:2019-11-13 06:13:06
【问题描述】:

目前这是我的代码:

from pptx import Presentation
from pptx.util import Pt

f = open(r'template.pptx', 'rb')
prs = Presentation(f)
f.close()

slide = prs.slides.add_slide(prs.slide_masters[0].slide_layouts[1])

title = slide.placeholders[10]
title.text = "REPORT"

prs.save('test.pptx')

如何将“报告”标题文本格式化为黄色和粗体?

【问题讨论】:

  • 您能给我们template.pptx,以便我们试用您的代码吗?

标签: python powerpoint python-pptx


【解决方案1】:

使用title.font访问字体属性:

from pptx.dml.color import RGBColor # add this import to the top of the file

title.font.bold = True
title.font.color.rgb = RGBColor(0xFF, 0xFF, 0x00)

【讨论】:

  • 对我有用的是:title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0xFF, 0xFF, 0x00)
猜你喜欢
  • 2022-10-15
  • 2014-09-03
  • 2023-01-28
  • 2023-01-28
  • 1970-01-01
  • 1970-01-01
  • 2016-03-27
  • 1970-01-01
  • 2012-06-18
相关资源
最近更新 更多