python - 如何在 python-pptx 中更改幻灯片标题的字体?
问题描述
我想更改幻灯片标题的字体大小和字体样式。我还想在标题下划线。怎么做?
from pptx import Presentation
prs = Presentation(ppt_filename)
slide = prs.slides[0]
slide.shapes.title.text = 'New Title'
slide.shapes.title.top = 100
slide.shapes.title.left = 100
slide.shapes.title.height = 200
解决方案
这可能有点hacky,但它有效。
根据文档,您可以访问标题占位text_frame
符形状。
多亏了这一点,您可以Paragraph
使用该属性在此框架内获取对象paragraphs
。在此处的元素部分中,您可以看到title
占位符形状位于第一个索引中(如果存在)。
然后我们现在可以获取Font
段落中使用的内容,并更改它的不同属性,如下所示:
from pptx import Presentation
from pptx.util import Pt
prs = Presentation(ppt_filename)
slide = prs.slides[0]
slide.shapes.title.text = 'New Title'
slide.shapes.title.top = 100
slide.shapes.title.left = 100
slide.shapes.title.height = 200
title_para = slide.shapes.title.text_frame.paragraphs[0]
title_para.font.name = "Comic Sans MS"
title_para.font.size = Pt(72)
title_para.font.underline = True
额外参考:
推荐阅读
- android - 如何加入具有不同 CONTENT_ITEM_TYPE 但共享一个公共字段的记录,即 RAW_CONTACT_ID?
- c - 为什么我不能将一个数组复制到另一个数组?
- java - 如何解决android电子邮件意图问题?
- linux - envsubst 仅适用于部分变量
- c# - 如何将双精度值从 html 输入传递到 C# 控制器
- sqlite - QT SQLite 无法获取表信息
- tensorflow - 如何将低级代码从 TF 1 转换为 TF 2
- scala - 为什么我必须传递 new 关键字?
- angular - 有条件地链接多个 observables 的更简洁的方法
- vue.js - 使用 Webpack 4 在 Phoenix 1.4 应用程序中安装 Vue 2