Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...