作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何遍历表并查找和替换文本?我能够浏览如下文本框,但需要能够访问和编辑表格中的信息:
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
j = 0
k = 0
for i in searchList:
#find the search term from the searchList
searchString = searchList[j]
j+=1
#replace the search term from the dataframe
dfIndexName = dfIndex.keys()[k]
k+=1
replaceString = df.at[0, dfIndexName]
if (shape.text.find(searchString))!=1:
text_frame = shape.text_frame
cur_text = text_frame.paragraphs[0].runs[0].text
new_text = cur_text.replace(searchString, str(replaceString))
text_frame.paragraphs[0].runs[0].text = new_text
最佳答案
我不确定你想用 searchList
做什么,但这是访问表格中单元格的方式。
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_table:
table = shape.table
for cell in table.iter_cells():
# here you can access the text in cell by using
# cell.text
# just remember that the shape object refers to the table in this context not the cell
关于python-3.x - 如何在python中使用pptx遍历表并编辑信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61533543/
我是一名优秀的程序员,十分优秀!