pythonexcelpowerpointxlwingspython-pptx

Export chart as image with python xlwings


I have been working on creating Excel reports automatically using Python and xlwings. Within these reports there are multiple charts and graphs which I now want to use in a pptx presentation keeping the same formatting and design. For the generation of the pptx I am currently using python-pptx.

An ideal solution would be to export the graphs directly from Excel to Powerpoint using xlwings, python-pptx, or some other library, maintaining the format and design of the graphs and keeping the dataset editable within the presentation.

A second solution would be to export the graphs while they are being created in the Excel report to a temporary folder as images. Then, use python-pptx to upload these images to the presentation. These would ensure keeping the design of the graphs but would mean that the data may not be edited. For this, I would need to know how to save charts as images with xlwings which I can't find a way to do so.

I am open to different solutions, including scraping over the generated Excel with a different language (a priori and without investigation, I would guess C# could be pretty good with windows apps). Although this would mean increasing the understanbility of the project as a whole.

Thanks very much in advance


Solution

  • You can implement a solution based on xlwings by falling back to the underlying pywin32 object and by adopting the solution from VBA, see e.g.: https://stackoverflow.com/a/11939249/918626

    To learn about how to work on the underlying pywin32 object, see: http://docs.xlwings.org/en/stable/missing_features.html