Python Pptx-修改现有表 [英] Python Pptx - Modify Existing Table

查看:932
本文介绍了Python Pptx-修改现有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对python-pptx模块非常陌生,所以请原谅我的无知.我正在尝试修改PowerPoint文件中的现有表,但是我在文档中没有找到可以执行此操作的地方.

I'm very new to the python-pptx module, so please excuse my ignorance. I'm trying to modify an existing table in a PowerPoint file, but I don't see anywhere in the documentation where I can do this.

我看到可以在哪里使用add_table()方法创建新表,但是我只需要使用Pandas数据框中的数据修改现有表即可.

I see where you can use the add_table() method to create a new table, but I only need to modify an existing table with data from a Pandas dataframe.

推荐答案

一旦获得形状ID(如Saleh所述),您可以修改表格单元格,如下所示:
对于幻灯片0,其形状ID为6,将第一个单元格(0,0)更改为"Pina Colada":

Once you get the shape id, as Saleh mentioned, you can modify table cells like this:
For slide 0, the shape id 6, changing the first cell (0,0), to 'Pina Colada':

Presentation('yourpowerpoint.pptx').slides[0].shapes[6].table.cell(0,0).text= 'Pina Colada'

这篇关于Python Pptx-修改现有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆