from pptx import Presentation
ppt=Presentation(path)
# 获取第24张幻灯片
slide=ppt.slides[23]
# 获取图表索引
for shape in slide.shapes:
if shape.has_chart:
chart = shape.chart
plot=chart.plots[0]
series=plot.series[0]
values=(1,2,3)
chart.plots[0].series[0].values=values
出现报错
File "D:/pythonProject/1003ppt自动化/pptx_demo修改.py", line 76, in <module> chart.plots[0].series[0].values=values AttributeError: can't set attribute
修改后的代码(参考的解决方案):
from pptx.chart.data import ChartData
解决方法二:将python pptx版本升级到最新版