PPT的一张幻灯片里有文字和图片。我想将图片设置为底层/将文本设置为顶层并查看文本内容。如何做到这一点?
text_frame = shape.text_frame
text_frame.vertical_anchor = MSO_ANCHOR.TOP
text_frame = shape.text_frame
text_frame.vertical_anchor = MSO_ANCHOR.TOP
text_frame.paragraphs[0].runs[0].text = "text"
left = Inches(5)
height = Inches(5.5)
pic = slide.shapes.add_picture(img_path, left, top, height=height)在PPT中让图片在底层,文本在顶层。
发布于 2019-10-29 12:57:21
幻灯片上的层将按照代码中的顺序显示。可以根据需要通过定义图层深度进行自定义。
from pptx import Presentation, shapes, slide
from pptx.util import Inches
img_path = 'image.png'
prs = Presentation()
blank_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(blank_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "Welcome to python-pptx!"
left = Inches(1)
height = Inches(4)
width = Inches(6)
top = Inches(1)
picture = slide.shapes.add_picture(img_path, left, top, height=height)
# Using layer sequence number to customize the depth
# sending the picture back in this case
slide.shapes._spTree.insert(2, picture._element)
prs.save('test.pptx')https://stackoverflow.com/questions/58601247
复制相似问题