我正在尝试更改PPT条形图系列数据,为此,我正在使用Python更改PPT的xml。
我正在遍历图表系列,并且能够更改这些数据,如下所示。
ser.xpath('./c:cat//c:pt/c:v')[1].text = "Some Category"
ser.xpath('./c:cat//c:pt/c:v')[2].text = "Cat 3"
ser.xpath('./c:cat//c:pt/c:v')[3].text = "cat 4"
但是问题是,当我单击PPT文件中的+(Edit)按钮时,它再次出现在默认图表中,并且被python程序覆盖的所有数据都消失了。
在这种情况下,谁能说出如何使用python保存PPT的xml。
xpath
也有保存方法吗?
我们如何重现此问题?
打开一个ppt并默认选择一个条形图并保存。
然后使用Python-pptx
阅读幻灯片,使用pip install python-pptx安装
from pptx import Presentation
prs = Presentation('file.pptx')
fifteen = prs.slides[0]
for shape15 in fifteen.shapes:
try:
print shape15.placeholder_format
except:
if shape15.has_chart:
chart = shape15.chart
for cnt, ser in enumerate(chart._chartSpace.xpath('//c:ser')):
ser.xpath('./c:cat//c:pt/c:v')[1].text = "Some other 889cat"
ser.xpath('./c:cat//c:pt/c:v')[2].text = "Cat 3"
ser.xpath('./c:cat//c:pt/c:v')[3].text = "cat 4"
打开文件时
当我点击过滤器