We have various spreadsheets that employ deliciously complicated macros and third party extensions to produce complicated models. I’m working on a project that involves slightly tweaking various inputs and seeing the results. Rather than doing this by hand or writing VBA, I’d like to see if I can write a python script to drive this. In other words, the python script will start up, load the excel sheet, and then interact with the sheet by making minor changes in some cells and seeing how they affect other cells.
So, my question is twofold:
-
What is the best library to use to drive excel from python in such fashion?
-
Where’s the best documentation/examples on using said library?
Cheers, /YGA
For controlling Excel, use pywin32, like @igowen suggests.
Note that it is possible to use static dispatch. Use
makepy.pyfrom the pywin32 project to create a python module with the python wrappers. Using the generated wrappers simplifies development, since for instance ipython gives you tab completion and help during development.Static dispatch example:
Documentation links: