I am using the python-pptx package to read a PowerPoint presentation into Python. There isn't native support to insert a row (or column) onto a table object. Although many individuals, per GitHub thread below have come up with a similar workaround to this:

from pptx import Presentation
from pptx.table import _Cell

prs = Presentation('test.pptx')
TAB = prs.slides[1].shapes[1].table
copy_idx=0
insert_idx=1
new_row = copy.deepcopy(TAB._tbl.tr_lst[copy_idx])
for tc in new_row.tc_lst:
    cell = _Cell(tc, new_row.tc_lst)
    cell.text = 'foobar'
TAB._tbl.append(new_row)
prs.save('test.pptx')

https://github.com/scanny/python-pptx/pull/399

When you then open the PowerPoint presentation, if you click in the row added and begin typing, it will modify the text in the 1st row, not the newly added row. Saving, and restarting the application makes the issue go away. However this isn't good enough when I need to keep working on the Presentation object in python without having to stop to manually reboot PowerPoint.

0

There are 0 answers