我想使用圖片占位符自動(dòng)替換 powerpoint 中的圖像我使用 python 使其動(dòng)態(tài)化,但我遇到了這樣的錯(cuò)誤:Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'LayoutPlaceholder' object has no attribute 'insert_picture'我使用的代碼如下: from pptx import Presentation
from pptx.util import Inches from PIL import Image
prs = Presentation(r'..\gambar\base_master_mod.pptx')
slide = prs.slide_layouts[0]
placeholder = slide.placeholders[1] # id key, not posisition
placeholder.name
placeholder.placeholder_format.type
picture = placeholder.insert_picture("..\output_graphics\image_res.png")這里是我使用的 powerpoint:這里如何解決問題?
1 回答

慕萊塢森
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
將第 5 行更改為:
slide = prs.slides[0]
看看這是否能讓你更接近。您可能仍然需要使用占位符 id 來弄清楚它們是什么。你可以做這樣的事情來列出它們。
for ph in slide.placeholders: print("placeholder %d has name: %s" % (ph.placeholder_format.idx, ph.name)
布局占位符與具有不同行為的幻燈片占位符不同。該.insert_picture()
方法僅適用于幻燈片圖片占位符。這就是它說的原因LayoutPlaceholder has no attribute 'insert_picture'
。
添加回答
舉報(bào)
0/150
提交
取消