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.
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.
There are multiple ways to select a shape in
python-pptx
. The best way to go around this is to know the id of the shape, you can get the id either by opening up the xml and finding the shape, or you can loop over all the shapes in the slide and print the id that way. However, you can still select the shape without knowing its id.If you know the shape id, you can search the slide for that shape's id, something like this will return the shape you want.
If you don't know the shape id, there are a few ways to get the shape, they're all a bit hacky, but they will all work.
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':