首页 > 解决方案 > 如何使用 pptx-python 库更改标题位置?

问题描述

我正在尝试将带有标题的文本框从中心移动到幻灯片的顶部。我无法为我的脚本找到正确的参数。以下是一些与之相关的行:

#setting slide type "Title and Content"
title_only_layout = pptx.slide_layouts[1]

#Adding content into the title box
pptx.slides.add_slide(title_only_layout)
pptx.slides[idx].shapes.title.text = "I am a title!"

这些命令将标题框添加到卡片组的中心。如何调整此脚本?

标签: pythonpython-pptx

解决方案


正如 Tim.Lucas 所提到的,幻灯片标题是一个占位符,它与任何其他形状一样具有.left.top.width和 。height您可以设置对象的位置和大小的属性。

from pptx.util import Cm

title = slide.shapes.title
title.top = Cm(3)
# ... and likewise for other position and size attributes

推荐阅读