Open buenohernandez opened 1 year ago
Isn't that because there's more to python-pptx's object model than chunks of XML?
To the OP's point, why XML rather than the calls python-pptx offers? I'm trying to understand the requirement.
It starts with a call like this:
newTableShape = slide.shapes.add_table(rows, columns, 0, 0, 0, 0)
(from my md2pptx project - which makes tables from Markdown).
It is terrible using this on mobile, so easy to misclick.
So, let's say you have pandas generated dataframes, and they have different styling, that maybe can be converted into xml. How would automate a crration of several tables on a slides using that exact styling (color, stripes, aligment) but having different shapes? And one of the requirements of this solution is it being generic, in other words hard coding a new template everytime it appears is out of question.
Did I help you understand?
Since you are here, I kindly accept suggestions.
I think most of the table attributes you could want are supported by python-pptx. (Not being the developer I can't claim all could be.)
When you create tables, rows, cells - which python-pptx certainly supports - you would have to parse the attributes from the input and apply them. And cells contain collections of runs - which can be individually styled.
(Note: My md2pptx doesn't pretend to copy attributes - other than alignment and width - as it's generating tables from Markdown.)
I already have a full functioning table_from_df, and it outputs a quite pretty table, my issue is that the template is hard coded and everytime a new template is needed I will have to recode it.
That is why I was looking for a "one size fits all" solution.
You gave me an idea, I can have the wanted table template made by hand (by the user) as a placheholder and my code just inserts the values 🤔.
Thank you!
And I will look into your code, there's probably more insights for me there.
That would work. It is easy to find the table on the slide in code.
I took the view most users of md2pptx would be leaning on their template presentation's styling - with the occasional override. Alignment and column widths are the obvious ones. But borders are another, subtler one. As is stripey rows.
It didn't work, I got stuck on obtaining properties like, bold, size, and font name, they all return None. It should be easy but its not that simple
Or for example, setting table.element.xml = xml_specimen (This doesn't work)