2

I am trying to automate a ppt using pptx-python library. I'm using a template. There are few charts in some of the slides. And charts have text boxes in it. I tried looping over the shapes to get the shape_id of those text boxes but I couldn't find the shape_id.

And when I tried to drag the text box out of the chart area it didn't come out. It seems the text box is part of the chart area. There are two areas chart area and plot area and text boxes are inside the chart area and plot area contains the bars of bar chart.

Original

[1]

When I shrink downed the plot area, the text boxes are still at there original position

[2]

Can anyone tell me how to locate those text boxes using python-pptx? I want to replace those XXX with my own text.

Text boxes are the part of the plot area.

Note: If this is already asked then please put up the link of that post in the comments. Thank you.

Added the XML Schema of the ppt you can see the text I want to replace. Can anyone tell me how to traverse through it using python-pptx?

Mr Anonymous
  • 75
  • 10
  • looks like maybe it's inside a group shape. Either ungroup them or traverse group shapes as encountered. – scanny Apr 23 '20 at 18:56
  • I tried searching for their shape id but it's in the chart so I couldn't, I check with all the group shapes in that slide but it's definitely not a group shape. – Mr Anonymous Apr 23 '20 at 19:00
  • @scanny But when I converted it into XML, I found all the XXX text boxes, but I don't know how to traverse through the XML schema, I don't know how to get to the text frame using python. – Mr Anonymous Apr 23 '20 at 19:03
  • @MrAnonymous Did you find any solution to this? text boxes inside of a chart? – destinychoice Apr 14 '21 at 11:42
  • @destinychoice No, I did not so I put text boxes using the dimensions its height, width, and left and right position which was almost similar to the largest bar I had in that bar chart. But I am sure it can be done by traversing through the XML schema. – Mr Anonymous Apr 14 '21 at 11:54
  • I see. I thought I chould do something like `shape.chart.text_frame` or `shape.text_frame` but I guess there's no support for text_frames inside of a GraphicFrame or Chart – destinychoice Apr 14 '21 at 12:02
  • yes, exactly the same thing I had faced. You can search about it on Github. There, people constantly talk about new features that need to be implemented and similar issues and maybe you can reach @scanny, he is one of the maintainers of the pptx-python. – Mr Anonymous Apr 14 '21 at 12:08

1 Answers1

0

It's an old question, but in case somebody else stumbles over this these days:

There are two possibilities for text being "in" a chart area:

  1. the text is a category name in the chart itself
  2. the text box is actually grouped with the chart and that makes it become a member of a special shape (GroupShape), that itself has a shapes attribute containing the chart and the text box.

Look at my answer at python-pptx - How to replace keyword across multiple runs? for a comprehensive solution to the years-old 'replace text in PowerPoint' problem. The script referenced there will be able to cover both of the points I listed above.

Frank
  • 884
  • 2
  • 10