我有以下代码:
from pptx import Presentation
ppt = Presentation('Powerpoint.pptx')
keyword = 'The'
replacement = 'Test'
import pandas as pd
def replace_text_by_keyword(ppt, keyword, replacement):
for slide in ppt.slides:
print(shp.has_text_frame)
print(str(shp.text))
for shp in slide.shapes:
if shp.has_text_frame and keyword in shp.text:
thisText = shp.text.replace(keyword, replacement)
shp.text = thisText
我想用替换替换所有关键字,但是我的代码不起作用,因为我的PowerPoint中有一个表
我的错误:
True
Insights
True
Process
True
False
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-113-92c22e9ec258> in <module>
----> 1 replace_text_by_keyword(ppt, keyword = 'a', replacement = 'b')
<ipython-input-111-59d21bcd0b65> in replace_text_by_keyword(ppt, keyword, replacement)
3 for shp in slide.shapes:
4 print(shp.has_text_frame)
----> 5 print(str(shp.text))
6 if shp.has_text_frame and keyword in shp.text:
7 thisText = shp.text.replace(keyword, replacement)
AttributeError: 'GraphicFrame' object has no attribute 'text'