python pptx复制指定页的ppt

python pptx复制指定页的ppt

如题,我有一个模板,我想根据需求复制模板中间的某一页多次,比如复制第五页,然后复制3次,那么第六页,第七页,第八页都是和第五页一模一样的ppt,次数是根据我的需求指定的,使用python pptx模块复制,可是不知道有没有相应的方法能实现,我用以下方法行不通:

prs = Presentation("Missed Assessment Rate Template.pptx") 

slide = prs.slides.add_slide(prs.slide_layouts[5])

prs.save("new.pptx")


回答:

搞定了!

def duplicate_slide(pres,index):

template = pres.slides[index]

blank_slide_layout = pres.slide_layouts[index]

copied_slide = pres.slides.add_slide(blank_slide_layout)

for shp in template.shapes:

el = shp.element

newel = copy.deepcopy(el)

copied_slide.shapes._spTree.insert_element_before(newel, 'p:extLst')

for _, value in six.iteritems(template.part.rels):

# Make sure we don't copy a notesSlide relation as that won't exist

if "notesSlide" not in value.reltype:

copied_slide.part.rels.add_relationship(value.reltype,

value._target,

value.rId)

return copied_slide

prs = Presentation("Missed Assessment Rate Template.pptx")

for i in range(0,3):

copied_slide = duplicate_slide(prs, 4)

prs.save("new.pptx")


回答:

报错了2333
newel = copy.deepcopy(el)
NameError: name 'copy' is not defined
请问copy是个什么呢

以上是 python pptx复制指定页的ppt 的全部内容, 来源链接: utcz.com/p/937721.html

回到顶部