How Can I Write Charts to Python DocX Document

John Rogerson picture John Rogerson · Jan 4, 2017 · Viewed 7.7k times · Source

python beginner here with a simple question. Been using Python-Docx to generate some reports in word from Python data (generated from excel sheets). So far so good, but would like to add a couple of charts to the word document based on the data in question. I've looked at pandas and matplotlib and all seem like they would work great for what I need (just a few bar charts, nothing crazy). But can anyone tell me if it is possible to create the chart in python and have it output to the word document via docx?

Answer

scanny picture scanny · Jan 4, 2017

The general approach that's currently supported is to export the chart from matplotlib or wherever as an image, and then add the image to the Word document.

While Word allows "MS Office-native" charts to be created and embedded, that functionality is not in python-docx yet.