python - 如何使用 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!"
这些命令将标题框添加到卡片组的中心。如何调整此脚本?
解决方案
正如 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
推荐阅读
- angular - 按内部 *ngFor 中的属性对整个 *ngFor 进行排序
- python - 如何处理在不同机器(路径)上处理一个项目?
- python - 使用 Zenpy 遍历带有列表的 API 时遇到问题
- python - 使用 tokenize.detect_encoding() 时出现“TypeError:对象不可调用”
- jquery - 响应式导航栏下拉菜单仅在悬停时打开而不是单击
- javascript - 防止 Showdown 修改某些分隔符之间的文本
- java - 安卓应用无法卸载。它不断使应用程序管理器崩溃
- python - 如何让cherrypy从索引和静态目录中提供静态文件,以及自定义路径?
- c# - C# 用 Char* 正确处理结构
- sql - 具有异或的左连接表