python-pptx icon indicating copy to clipboard operation
python-pptx copied to clipboard

feature: Table.add_row() and .add_column()

Open scanny opened this issue 10 years ago • 6 comments

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.

scanny avatar Apr 16 '14 01:04 scanny

Yes, this would be very useful!

ghost avatar May 05 '14 11:05 ghost

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.

adamtwiss avatar May 29 '14 13:05 adamtwiss

+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()

smcpherson avatar Jan 25 '16 23:01 smcpherson

https://github.com/scanny/python-pptx/pull/399 - here is my solution if someone would face the same need.

Ignisor avatar Jun 27 '18 12:06 Ignisor

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 be Table.cell(-1, -1).insert_column(side=RIGHT) although perhaps Table.add_row() and Table.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.

scanny avatar Sep 23 '18 22:09 scanny

Hi! Are there any news on this feature?

astafan8 avatar Feb 19 '24 13:02 astafan8