4

I have a powerpoint presentation with charts I want to update from python.

Right now I am using python-pptx library which is great but its chart.replace_data() the method is replacing the excel sheet with chart data in the chart.

Unfortunately, some of my charts have data labels calculated in separate cells (f.e I am using a normal bar chart but showing % value data labels with additional words in them, which are calculated alongside in excel).

Is there any alternative way to update chart data not affecting other cells of the excel sheet?

Bilaal Rashid
  • 828
  • 2
  • 13
  • 21
Agniy
  • 41
  • 3

1 Answers1

0

This feature is not supported in python-pptx and is unlikely to be added unless a project team wants to sponsor it. It's a legitimate use-case, just not common enough that most folks would want it bad enough to apply project budget.

If you wanted to dig into it, I expect you'd want to create a fork. You would need an Excel library that can read Excel (the current XlsxWriter package python-pptx uses is "write-only"), so that would be a new dependency.

You'd probably want to start from about here in the code:
https://github.com/scanny/python-pptx/blob/master/pptx/parts/chart.py#L65

It would not be a trivial undertaking. There would be a lot to map in as far as where the existing data was and what to do if the shape of the data changed (more/fewer rows/cols).

scanny
  • 26,423
  • 5
  • 54
  • 80