Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

powerpoint - Finding and using shape position Python pptx

I am trying to locate the position of a shape with specific text within it. After I get the position of the shape, I want to add an image at the same position as to highlight its location in the PowerPoint upon opening. Here is what I have so far:

from pptx import Presentation  
from pptx.util import Inches, Pt 

path_map = 'Path/TO.pptx'
prs = Presentation(path_map)
image_file = 'Path/TO.png'
search_str = 'Jack'
for slide in prs.slides:
    for shape in slide.shapes:
        if shape.has_text_frame:
            if(shape.text.find(search_str))!=-1:
                horiz_ = shape.left
                vert_ = shape.top
                height_ = Inches(1)
                width_ = Inches(1) 
                slide.shapes.add_picture(image_file, horiz_, vert_, width_, height_)
prs.save(path_map)

When run, no errors pop up, but the image is not added either, any suggestions on what I am missing?

question from:https://stackoverflow.com/questions/66049158/finding-and-using-shape-position-python-pptx

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...