使用python-pptx包批量修改ppt格式的实现
作者:六盘水月照 时间:2021-04-03 21:31:16
最近实习需要对若干ppt进行格式上的调整,主要就是将标题的位置、对齐方式、字体等统一,人工修改又麻烦又容易错。
因此结合网上的pptx包资料,使用python脚本完成处理。
主要的坑点在于,shape的text_frame不能直接修改字体,甚至paragraph也不行,由于一个框里多个字体存在,它会报为“None”,需要进一步去run层修改。
from pptx import Presentation
from pptx.enum.text import PP_ALIGN
prs = Presentation('originalppt.pptx') #导入ppt
sthead=prs.slides[2].shapes[1] #以第3张ppt为标准标题格式
print(sthead.text)
stleft=sthead.left
stwidth=sthead.width
sttop=sthead.top
stheight=sthead.height
#进行逐个修改
i=1
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
if 36000<shape.left<1200000 and shape.height<1400000:
ftname=(shape.text_frame.paragraphs[0].runs[0].font.name)
ftsize=int(shape.text_frame.paragraphs[0].runs[0].font.size.pt)
if (ftsize>27):
head=shape
head.left=stleft
head.top=sttop
head.width=10080000
head.height=stheight
head.text_frame.vertical_anchor = MSO_ANCHOR.MIDDLE
head.text_frame.paragraphs[0].line_spacing=1
for paragraph in head.text_frame.paragraphs:
for run in paragraph.runs:
run.font.size = 32*12700
run.font.name = '宋体'
#print(i,'ok')
i +=1
prs.save('adjnew.pptx') #保存修改后的ppt
来源:https://www.cnblogs.com/oikoumene/p/11201864.html
标签:python,pptx,ppt格式
0
投稿
猜你喜欢
Python进阶之使用selenium爬取淘宝商品信息功能示例
2022-04-26 04:55:15
Pytorch BertModel的使用说明
2023-06-28 09:30:37
pandas行和列的获取的实现
2022-06-05 07:57:49
Firefox插件推荐:CSS Usage
2009-10-26 18:44:00
python pptx复制指定页的ppt教程
2023-08-20 22:54:50
python Pillow图像处理方法汇总
2021-09-08 18:02:45
Python基于回溯法子集树模板解决m着色问题示例
2023-11-14 12:22:59
快速认识CSS中的overflow属性
2009-05-29 16:36:00
php ajax异步读取rss文档数据
2023-10-17 19:59:02
Python中return用法案例详解
2022-09-09 10:35:40
六个Python3中使用最广泛的内置函数总结
2021-12-06 09:12:34
python微信跳一跳系列之棋子定位颜色识别
2023-01-16 04:52:49
如何正确显示模式对话框showModalDialog中的中文?
2010-06-28 18:24:00
详解Python中的各种函数的使用
2022-03-23 22:09:52
基于python实现聊天室程序
2022-09-26 07:50:33
Iinternet Explorer浏览器简介(IE)
2009-02-05 20:59:00
PHP利用ChatGPT实现轻松创建用户注册页面
2023-05-25 09:22:16
python 密码验证(滑块验证)
2021-01-24 02:32:18
ie6下实现position-fixed效果
2009-06-05 18:47:00
Python实现字典的key和values的交换
2021-08-18 03:45:49