'Extract & Replace text for python-pptx graphicframe

I am extracting data from a slide, so for table, chart and normal shape which has a text frame, I am able to get text and replace it.

But when it comes to SmartArt, I am unable to fetch textenter code here

for shape in slide.shapes:
   print(shape.element.xml)

Is there any property of element or shape, where we can extract data from SmartArt ?



Solution 1:[1]

Aspose.Slides for Python makes it easy to extract text from nodes of a SmartArt object. The following code example shows you how to do this:

import aspose.slides as slides
import aspose.slides.smartart as smartart

# Load a presentation.
with slides.Presentation("example.pptx") as presentation:
    # Get the first shape from the first slide, for example.
    shape = presentation.slides[0].shapes[0]
    if type(shape) is smartart.SmartArt:
        # Extract text from all nodes.
        for node in shape.all_nodes:
            for node_shape in node.shapes:
                if node_shape.text_frame is not None:
                    print(node_shape.text_frame.text)

This is a paid product, but you can get a temporary license to evaluate all features of the library.

Alternatively, you can use Aspose.Slides Cloud SDK for Python that provides a REST-based API for managing presentations. It is also a paid product, but you can make 150 free API calls per month for experimentation, learning, and any other purpose. The following code example extracts all text from SmartArt nodes using Aspose.Slides Cloud:

import asposeslidescloud

from asposeslidescloud.apis.slides_api import SlidesApi

slides_api = SlidesApi(None, "my_client_id", "my_client_secret")

# Get the first shape from the first slide, for example.
shape = slides_api.get_shape("example.pptx", 1, 1)

if shape.type == "SmartArt":
    # Extract text from all nodes.
    for node in shape.nodes:
        print(node.text)

I work as a Support Developer at Aspose.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrey Potapov