Thursday 28 December 2017

Getting graphs from Excel to Word

One of the problems I wanted to tackle when I started using python-docx was replacing tools like Oracle BI Publisher. I have years experience with this and it is not that nice to use but its support for graphs and overall it does do the job. I have been using it to create monthly management reports to show progress against KPIs etc. So one thing that I needed to tackle was getting nicely formatted graphs in there. Step in XLwings. My basic process: 

  1. Create the required graphs in Excel. 
  2. Create SQL / XLwings scripts to update the graphs 
  3. Export the charts as pictures. 
  4. Insert the pictures into Word document. 
It is not the remit of this post to cover the first 2 steps in detail but rather focus on step 3 and step 4. 


The code:


No comments:

Post a Comment