python_拷贝PPT中的一张幻灯片到另一个PPT中
可以指定位置
from pptx import Presentation
import copy
from contextlib import redirect_stderr
import os
#pres_loc1_index是第一个PPT对应的索引值,如果是“all”,则表示所有
#pres_loc2_index是第二个PPT对应的索引值,如果是“all”,则表示所有
#目标是将第二个PPT中的指定幻灯片,拷贝到第一个PPT中的指定位置,结果保存到新的PPT中。
#不能复制图片,图片的话需要用单独的插入图片的函数
#一次只能从第二个PPT中复制一张幻灯片过去,因为多了会被覆盖,也就是如果pres_loc1_index不为“all”的情况下,pres_loc2_index不能为“all”
def remove_title_and_subtitle(slide):
# 遍历幻灯片上的形状(即元素)
for shape in slide.shapes:
if shape.has_text_frame:
# 如果形状是标题或副标题,则删除它
if "title" in shape.name.lower():
slide.shapes._spTree.remove(shape.element)
elif "subtitle" in shape.name.lower():
slide.shapes._spTree.remove(shape.element)
def clear_slide(slide):
# 清除形状
for shape in slide.shapes:
slide.shapes._spTree.remove(shape._element)
# 清除占位符
for placeholder in slide.placeholders:
slide.placeholders._spTree.remove(plac

3348

被折叠的 条评论
为什么被折叠?



