我正在尝试为我的幻灯片添加标题。我正在查找文档here http://python-pptx.readthedocs.io/en/latest/user/placeholders-using.html它说:“设置幻灯片标题
几乎所有幻灯片布局都有一个标题占位符,任何基于该布局的幻灯片都会在应用该布局时继承该标题占位符。访问幻灯片的标题是一项常见操作,形状树上有一个专用属性:
title_placeholder = slide.shapes.title
title_placeholder.text = 'Air-speed Velocity of Unladen Swallows'
"
实际上我的幻灯片布局没有 title_placeholder。
我运行此代码来找出我有哪些占位符:
for shape in slide.placeholders:
... print('%d %s' % (shape.placeholder_format.idx, shape.name))
并得到:
11 Text Placeholder 3
12 Text Placeholder 4
13 Text Placeholder 2
15 Text Placeholder 1
所以现在我想向这些占位符添加文本 - 其中之一是标题 - 我会弄清楚是哪一个。
该文档介绍了如何使用以下方法在占位符中插入表格、图片和图表insert_picture
, insert_table
等等,但是没有insert_text
.
如何添加文字?
In python-pptx
,占位符是以下子类Shape
(自动形状)。因此,规则形状(如矩形)的所有属性都可以在占位符上使用,特别是.text
and .text_frame
.
http://python-pptx.readthedocs.io/en/latest/api/shapes.html#shape-objects-autoshapes http://python-pptx.readthedocs.io/en/latest/api/shapes.html#shape-objects-autoshapes
因此,要更改占位符的文本,只需使用:
placeholder.text = 'foobar'
通常的方法是使用一个标题占位符,该占位符已针对标准标题外观进行了预先格式化。通常,标题占位符放置在用于创建幻灯片的幻灯片布局上,这样它就可以在演示文稿中一致显示。
使用标题占位符可确保其包含的文本用于在大纲视图和其他一些位置中标识幻灯片。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)