python/excel cell -> png
Question: Folks, There is an excel document that needs weekly updating... Just a few
cells that need to be updated, which is totally doable via:
<http://www.python-excel.org/>

After these cells are updated, a graph is generated inside excel. Is it
possible to export this graph into a .png via python (ie, copy cells A3-B7 and
export into an image)?

Thoughts, ideas?

Thanks!


Answer: You could export an existing chart to PNG using [COM
extensions](http://sourceforge.net/projects/pywin32/). You will have to make
sure the chart has been already updated with the new data before exporting.

I found this discussion of the `Charts` object helpful:
<http://msdn.microsoft.com/en-us/library/aa213725(v=office.11).aspx>

You would up with something like this (untested code):

    
    
    from win32com.client import Dispatch
    xlsApp = Dispatch("Excel.Application") 
    xlsWB = xlsApp.Workbooks.Open(r'C:\TEST\WorkbookWithAChart.xlsx') 
    xlsSheet = xlsWB.Sheets("Sheet 1") 
    mychart = XlsSheet.Charts(1)  #'1' is the index of the chart object in the wb
    mychart.Export(Filename=r'C:\TEST\MyExportedChart.png') 
    

Helpful references:

  * [Quick Start to Client side COM](http://docs.activestate.com/activepython/2.4/pywin32/html/com/win32com/HTML/QuickStartClientCom.html)
  * [Win32COM Documentation](http://docs.activestate.com/activepython/2.4/pywin32/html/com/win32com/HTML/docindex.html)

