python-pptx icon indicating copy to clipboard operation
python-pptx copied to clipboard

added Slides.remove_slide(slide_id)

Open RaulSofia opened this issue 1 year ago • 0 comments

Adds the delete slide feature. You can do this by calling the method Slides().remove_slide(slide_id) on a Slides instance. It deletes a slide and relations, doing just the opposite of the routines in add_slide(). This function calls PresentationPart().remove_slide(slide_id) and CT_SlideIdList().remove_sldID(slide_id), which were also added here. It raises a KeyError(f"no slide with id {slide_id}") if the specified slide_id does not exist.

Fixes issue #67

Example usage:


from pptx import Presentation

presentation = Presentation()
presentation.slides.add_slide(presentation.slide_layouts[6])
presentation.slides.remove_slide(presentation.slides[-1].slide_id) #removes last slide
presentation.save("my_presentation.pptx")

#output: empty presentation (no slides)

RaulSofia avatar Nov 16 '24 22:11 RaulSofia