I am trying to change the PPT bar chart series data and for that I am changing the xml of PPT using Python.
I am iterating over chart series and I am able to change these data Something like below.
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"
But problem is when I click on +(Edit) button in PPT files it again comes to it default chart and all data overwritten by python program get vanished.
Can anyone tell how to save a xml of PPT using python in this case.
Does xpath
has save method too ?
How can we reproduce this problem ?
Open a ppt and select a bar chart by default and save it.
Then read the slide using Python-pptx
install using 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"
When I open the file
When I click on the filter