使用python-pptx包追加表格行将添加一行,在PowerPoint中进行编辑时会更改另一行的内容

问题描述

我正在使用python-pptx包将PowerPoint演示文稿读入Python。没有本机支持将行(或列)插入到表对象中。尽管个人很多,但每个GitHub线程都提供了与此类似的解决方法

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

然后打开PowerPoint演示文稿时,如果单击添加的行并开始键入,它将修改第一行中的文本,而不是新添加的行。保存并重新启动应用程序使问题消除了。但是,当我需要继续使用python中的Presentation对象而不需要停止手动重新启动PowerPoint时,这还不够。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)