0

Code to import data from table and text frame:

 pres = Presentation(ppt_file)

    for slide in pres.slides:
        for shape in slide.shapes:
            if(shape.has_text_frame):
                for paragraph in shape.text_frame.paragraphs:
                    for run in paragraph.runs:
                        print run.text    

I've a slide like this:

enter image description here

Output is: Running text

Text is being read from the left frame or the big box but not from the two right frames.

skrubber
  • 1,095
  • 1
  • 9
  • 18
  • This should be two questions. Check that the two right frames are not group shapes. – scanny Jun 07 '17 at 19:23
  • Also check that A and B are actual text and not part of an image. – scanny Jun 07 '17 at 19:24
  • @scanny: Yes A and B are text. The images are placed above the text. Merged the two questions as I didn't want to be redundant. – skrubber Jun 07 '17 at 19:28
  • These are two separate problems. Which one do you want me to address? – scanny Jun 07 '17 at 20:58
  • @scanny Problem 2 please – skrubber Jun 07 '17 at 20:59
  • If you make it a separate question and tag it with 'python-pptx' I'll see it. Make sure you show the code you use and the results you get. – scanny Jun 07 '17 at 22:16
  • @scanny: edited the question itself to reflect only one. the code is the same. There is no output for the left frame. – skrubber Jun 08 '17 at 04:32
  • Check to see what type the other shapes are. Right after the `for shape in slide.shapes:` add the line `print(shape.shape_type)`. I have an idea you'll find they are group shapes, which are unfortunately not supported in `python-pptx` yet. – scanny Jun 08 '17 at 04:38
  • @scanny This is what I get: TEXT_BOX (17) None AUTO_SHAPE (1) AUTO_SHAPE (1) None AUTO_SHAPE (1) AUTO_SHAPE (1) None None . So I assume None is a grouped shape? – skrubber Jun 08 '17 at 05:31

1 Answers1

2

The shapes that are reporting None as their shape type are Group shapes. You can confirm this by printing out their XML:

print(shape._element)  # should give something like 'CT_GroupShape'
print(shape._element.xml)  # should show XML that starts with `<p:grpSp>`

Group shapes aren't yet supported in python-pptx. If you can ungroup them in PowerPoint their text will be accessible.

UPDATE: A group shape has no text. However, you can use group_shape.shapes to iterate over the shapes inside the group and access their text. Note that groups can contain other groups.

scanny
  • 26,423
  • 5
  • 54
  • 80