I've managed to read an existing .pptx file in Python using python-pptx and i can access the tables in the powerpoint slides.
What i fail to do: Get the border color of a cell.
I want to insert data in table cells depending on the tables border color, e. g. in a table cell with green borders, insert "111" and in a cell with red borders insert "222".
Inserting values works, but without checking the tables (or cells) border color, the data ends up in wrong places.
There is more than one table on a ppt slide. The tables are all in unique border colors, e. g. one table has solid green borders all around, another one is completely green, another one blue, and so on.
This is how i iterate the page tables and access cells:
from pptx import Presentation
pptx_file = r"my_file_here"
with open(pptx_file, "rb") as pptx:
prs = Presentation(pptx)
for slide in prs.slides:
for shape in slide.shapes:
if not shape.has_table:
continue
table = shape.table
my_input_field = table.cell(0, 1)
I want to insert in my_input_field
based on the color, but don't know how to get/check/read it's border color?
I'm afraid i'm too stupid to handle the infos there, that doesn't help me: https://python-pptx.readthedocs.io/en/latest/api/dml.html#pptx.dml.color.ColorFormat
Can someone point me in the right direction?
Edit:
I'm pretty sure there is a way to access the color. The docs state:
cell
A cell has a background fill, borders, margins, and several other formatting settings that can be customized on a cell-by-cell basis.
But i couldn't figure how to access this properties. I've had a look at the code snippets that set a color, but i can't make any sense out of this examples.
Edit 2: My Workaround
I've still no solution, but in case someone stumbles upon this - here is my little workaround: I put the color name of a table in the table itself, as text.
When iterating all tables, i read this text from the table and delete it there. This way i can distinguish the tables and add the correct informations.
It's not really nice, but it works.