Using copy.deepcopy with python-pptx to add a column to a table leads to cell attributes being corrupted

If you’re serious about solving this sort of problem, you’ll need to reverse-engineer the Word XML for this aspect of tables.

The place to start is with before and after (adding a column) XML dumps of the table, identifying the changes made by Word, then duplicating those that matter (things like revision-numbers probably don’t matter).

This process is simplified by having a small example, say a 2 x 2 table to a 2 x 3 table.

You can get the XML for a python-docx XML element using its .xml attribute, like:

print(tab._tbl.xml)

You could compare the deepcopy results and then have concrete differences to start to explain the results not working. I expect you’ll find that table items have unique ids and when you duplicate those, funky things happen.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top