0

How to delete a power point slide by finding a specific string character in python? I have a string named "abc".Now if this string is available in any slide then that slide will delete automatically. How to resolve this issue as I am a total beginner and need help.

Shaon
  • 133
  • 1
  • 13

2 Answers2

0

As at August 14, 2019 there is certain feature request on GitHub, however there is no python-pptx solution for deleting a slide from presentation yet.

Oskar_U
  • 472
  • 4
  • 13
0

You can use Aspose.Slides for Python to find and remove all the slides in a presentation that contain the specified text at once. The following code example shows you how to do this:

import aspose.slides as slides

file_name = "example.pptx"
my_text = "abc"

# Collect all text from the presentation.
all_text = slides.PresentationFactory().get_presentation_text(file_name, slides.TextExtractionArrangingMode.UNARRANGED)

# Load the presentation.
with slides.Presentation(file_name) as presentation:

    # Find all slides containing the specified text.
    slides_to_remove = []
    for index, slide in enumerate(presentation.slides):
        # Looking for the text in presentation slides only (ignore masters, lyouts, notes).
        if my_text in all_text.slides_text[index].text:
            slides_to_remove.append(slide)

    # Remove the found slides.
    for slide in slides_to_remove:
        presentation.slides.remove(slide)

    # Save the presentation.
    presentation.save(file_name, slides.export.SaveFormat.PPTX);

This is a paid package, but you can get a temporary license or use it in trial mode to evaluate all features for managing presentations. I work as a Support Developer at Aspose and will be happy to answer your questions on Aspose.Slides forum.

Andrey Potapov
  • 29
  • 2
  • 14