首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python模块

Python模块
EN

Stack Overflow用户
提问于 2014-04-07 12:29:36
回答 1查看 3.3K关注 0票数 1

我必须编辑一个pptx模板,其中包含如下表:

如何将存储在python中的值附加到空字段?我正在使用pptx模块,但是我找不到任何这样做的例子。

代码语言:javascript
复制
from pptx import Presentation


prs = Presentation('template.pptx')
slide = prs.slides[2] #<- This is the slide that contains the table
shape = slide.shapes #<- As I understood This gives access to the shapes
textframe=shape.textframe
textframe.clear()

prs.save('test.pptx') #<- Saves the new file

pptx模块链接

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-09 09:37:22

引用python-ppty developer的dev-group

-if --你知道它的索引,类似于table = slide.shapes[2]的东西--就能做到这一点。然后,您需要在更改单元格的内容之前导航它们:

代码语言:javascript
复制
for idx, row in enumerate(table.rows):
    if idx = 0:  # skip header row
        continue
    name_cell = row.cells[0]
    name_cell.text = 'foobar'
    corners_cell = row.cells[1]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22912467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档