python-pptx
python-pptx copied to clipboard
feature: Table.add_row() and .add_column()
Ability to dynamically add to a table, especially adding a row, is very handy when pulling records from a datasource where the length of the list may vary.
Yes, this would be very useful!
This is exactly what I am looking for as well. My use case is I have a variable number of records (but small enough to fit on one slide) and I want to add a table row for each tiem.
+1 - would be very useful, as it could potentially allow for table formatting to be done in powerpoint template, while insertion of rows / columns could be done dynamically via Table.add_row()
https://github.com/scanny/python-pptx/pull/399 - here is my solution if someone would face the same need.
A few notes based on my recent study of tables:
-
Adding a row or column should be fairly straightforward. Inserting a row or column at an arbitrary position might be somewhat more challenging but is probably a better choice.
The challenge here would be how to deal with merged cells. The PowerPoint UI seems to have pretty clear semantics about how to deal with merged cells, which is basically extending the merge to incorporate the new row or column when it comes in the middle of the merge-region.
API might be
_Cell.insert_column(side=LEFT)
etc. Adding a row or column would just beTable.cell(-1, -1).insert_column(side=RIGHT)
although perhapsTable.add_row()
andTable.add_column()
convenience methods would be worthwhile. -
Deleting a row or column would be complicated by merged cells and hyperlinks. Again, the PowerPoint UI semantics appear pretty clear, so the behavior would be well defined. Merged cells would need to be "shrunk" in certain scenarios and multiple grid rows/columns would need to be deleted when the cell was a merge-origin.
Any hyperlinks encountered in table content would need to be deleted from the relationships collection for the slide. I think that's the only related content there could be.
Hi! Are there any news on this feature?