Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting slides at a specific position in presentation #274

Closed
sarwatfatimam opened this issue Apr 1, 2017 · 2 comments
Closed

Inserting slides at a specific position in presentation #274

sarwatfatimam opened this issue Apr 1, 2017 · 2 comments

Comments

@sarwatfatimam
Copy link

Hi,

I was wondering if the feature for adding a slide at a specific position has been developed. The docs read, "At the time of writing it’s the only way to add a slide, but sooner or later I expect someone will want to insert one in the middle, and when they post a feature request for that I expect I’ll add an insert_slide (idx, ...) method."
If this feature has not yet been developed, can someone please add this feature?

@blaze33
Copy link

blaze33 commented Apr 24, 2017

There's a way to do this:

class PresentationBuilder(object):

    presentation = Presentation("your_presentation.pptx")

    @property
    def xml_slides(self):
        return self.presentation.slides._sldIdLst  # pylint: disable=protected-access

    def move_slide(self, old_index, new_index):
        slides = list(self.xml_slides)
        self.xml_slides.remove(slides[old_index])
        self.xml_slides.insert(new_index, slides[old_index])

    # also works for deleting slides
    def delete_slide(self, index):
        slides = list(self.xml_slides)
        self.xml_slides.remove(slides[index])

Now you can add a slide to the end (default behavior) and use move_slide(-1, x) to insert it at the right place.

@scanny
Copy link
Owner

scanny commented Apr 24, 2017

Duplicate of #68

@scanny scanny closed this as completed Apr 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants