I already referred these posts here here, here and here. Please don't mark it as a duplicate.
I have a chart embedded inside the ppt like below
I wish to replace the axis headers from FY2021 HC to FY1918 HC. Similarly, FY2122 HC should be replaced with FY1718 HC.
How can I do this using python pptx? This chart is coming from embedded Excel though. Is there anyway to change it in ppt?
When I tried the below, it doesn't get the axis headers
text_runs = []
for shape in slide.shapes:
if not shape.has_text_frame:
continue
for paragraph in shape.text_frame.paragraphs:
for run in paragraph.runs:
text_runs.append(run.text)
when I did the below, I find the list of shape types from the specific slide. I wish to change only the chart headers. So, the screenshot shows only two charts that I have in my slide.
for slide in ip_ppt.slides:
for shape in slide.shapes:
print("id: %s, type: %s" % (shape.shape_id, shape.shape_type))
id: 24, type: TEXT_BOX (17)
id: 10242, type: TEXT_BOX (17)
id: 11306, type: TEXT_BOX (17)
id: 11, type: AUTO_SHAPE (1)
id: 5, type: TABLE (19)
id: 7, type: TABLE (19)
id: 19, type: AUTO_SHAPE (1)
id: 13, type: CHART (3)
id: 14, type: CHART (3)
When I try to access the shape using id, I am unable to as well
ip_ppt.slides[5].shapes[13].Chart
I also tried the code below
from pptx import chart
from pptx.chart.data import CategoryChartData
chart_data = CategoryChartData()
chart.datalabel = ['FY1918 HC', 'FY1718 HC']
Am new to python and pptx. Any solution on how to edit the embedded charts headers would really be useful. Help please
from python ppt find and replace within a chart

No comments:
Post a Comment