python - xpath Python:系列数据不会永久保存在PPT中
问题描述
我正在尝试更改 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"
当我打开文件
当我点击过滤器时
解决方案
推荐阅读
- asp.net - 在负载均衡器后面时签名验证失败
- embed - Google Docs 删除标题和页脚
- php - 多个 Laravel App 使用同一个表作业
- python - 如何使用python关闭Windows 10中打开的端口?
- php - Mpdf加载一次然后不起作用
- excel - 使用 Excel 数据透视表分析每周详细报告
- python - 从二进制文件中读取可变长度的 numpy 数组
- ecmascript-6 - Java Nashorn 和 ECMAScript 6 for..of:ECMAScript 异常:SyntaxError:预期;但发现
- c# - 将 API 请求添加到按钮
- html - 为什么导航与其他导航不在同一条线上?