簡體   English   中英

python-pptx:將圖片插入內容占位符

[英]python-pptx: insert picture into content placeholder

我正在使用 python-pptx 0.6.0,我創建了一個帶有標題內容的幻燈片。 我想將圖片插入到內容占位符中,但沒有使用 add_picture 或 insert_picuture 等屬性。 如何將圖片添加到此內容占位符中? 感謝您回答我的問題:)

請參閱了解占位符使用占位符的文檔。

簡而言之,使用類似的方法,您可以從幻燈片中獲取占位符,然后在占位符上調用insert_picture

>>> prs = Presentation()
>>> slide = prs.slides.add_slide(prs.slide_layouts[8])
>>> placeholder = slide.placeholders[1]  # idx key, not position
>>> placeholder.name
'Picture Placeholder 2'
>>> placeholder.placeholder_format.type
PICTURE (18)
>>> picture = placeholder.insert_picture('my-image.png')

請注意,這僅適用於圖片占位符。 您需要將任何“通用”內容占位符替換為特定於您要插入的內容的占位符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM