Last active
May 19, 2025 06:19
-
-
Save robintw/3df1464e5c8a7ee8835e to your computer and use it in GitHub Desktop.
Duplicate slide in python-pptx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def duplicate_slide(pres, index): | |
source = pres.slides[index] | |
try: | |
blank_slide_layout = pres.slide_layouts[6] | |
except: | |
blank_slide_layout = pres.slide_layouts[len(pres.slide_layouts) - 1] | |
dest = pres.slides.add_slide(blank_slide_layout) | |
for shp in source.shapes: | |
el = shp.element | |
newel = copy.deepcopy(el) | |
dest.shapes._spTree.insert_element_before(newel, 'p:extLst') | |
for key, value in source.rels.iteritems(): | |
if not "notesSlide" in value.reltype: | |
dest.rels.add_relationship(value.reltype, value._target, value.rId) | |
return dest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code works in version 0.6.19 and below:
Does anybody have a version which works with more recent versions ? (1.0.0 and up)