• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

使用python-pptx包批量修改ppt格式的实现

python 搞代码 4年前 (2022-01-08) 18次浏览 已收录 0个评论

今天小编就为大家分享一篇使用python-pptx包批量修改ppt格式的实现,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

最近实习需要对若干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.height27): head=shape head.left=stleft <p style="color:transparent">来源gao!%daima.com搞$代*!码网</p>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

以上就是使用python-pptx包批量修改ppt格式的实现的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:使用python-pptx包批量修改ppt格式的实现
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址