I'd like to use the python-pptx library to read the embedded data sheet behind a chart inside a presentation. I've seen the documentation to replace chart data, but I can't figure out how to read data. I've already referred to Read chart data from existing chart using python-pptx but this is not what I'm looking for.
Asked
Active
Viewed 875 times
1 Answers
1
chart.part.chart_workbook.xlsx_part.blob
will give you the Excel binary (bytes).
From there you can save that as a file or read it as an in-memory file using io.BytesIO()
, or whatever suits your purposes.
You could, for example, open it with openpyxl
and read and write the Excel "file".

scanny
- 26,423
- 5
- 54
- 80
-
1Okay so I've been able to read data to an extent: `prs = Presentation(presentation_path) graphic_frame = prs.slides[2].shapes chart = graphic_frame[0].chart plot = chart.plots[0] category_labels = [c.label for c in plot.categories] series = plot.series[0] md = {} for i in range(0,len(plot.series)): md[plot.series[i].name] = list(plot.series[i].values) chart_data = CategoryChartData() chart_data.categories = [c.label for c in plot.categories] for key, value in md.items(): chart_data.add_series(key, [10*v for v in value]) chart.replace_data(chart_data) ` – Rajat Feb 10 '21 at 16:22
-
Would you say that accessing the slide>shape>graphic_frame>plot>series is one way of doing it? – Rajat Feb 10 '21 at 16:24