Automating Microsoft Office with Python
nbviewer.ipython.org
nbviewer.ipython.org
The silly and wonderful thing about the Office API is that it doesn't work silently, but instead performs the operations on screen as if they were being done by a human being. The article explains this. There's something very satisfying about seeing the reaction of your boss as he watches the computer do the work on its own, as if its being operated by a ghost. Now I know what it must have been like to see a player piano a hundred years ago.
ps: I don't know how Excel is structured these days but up until 2003 there was zero multicore code, and VBA is not the fastest system around, so any way you can trim the workload is good.
However, I haven't found a way of turning this off for PowerPoint. On the other hand, one of the weird quirks is that the API draws much faster if you keep the window dragged. I've spent a fair bit of time keeping the PowerPoint window dragged while Python drives COM!
I can say this too and we do stuff not even Microsoft thought was possible.
while the interface is powerful there are mysteries at every level.
The interfaces are indeed powerful (not to leave out annoyingly inconsistent). That said, there are only mysteries when you go oh so far. If play by a few safe rules, you should be mostly safe unless you have very long lived processes which starts mixing COM code with other code digging beneath the API for things which isn't otherwise possible.
It can be argued that both the best and the worst part of the .NET Framework is how it makes COM interop seem so utterly seamless. It's bound to land you in a trap sooner or later.
wordInstance.ActiveDocument.SaveAs(filename + ".pdf", 17)
17 is the magic number for PDF output. There is a constant in VSTO and COM for it but I can't remember what it is. Need Office 2007 with save as pdf addon installed or vanilla 2010/2013.People always say that APIs are the future and Microsoft are dead etc but Microsoft stuff is usually chock full of extensibility and knee deep in documentation. To give you an idea, it took me merely two days to extend word 2010 via VSTO with a fully GUI and ribbon integrated semantic template engine that allows documents to be bound to our public API and rendered server side or client side online and offline.
Do that in Google Apps? Yeah right...
also my solution will still be supported until 2023!
(which are linked within this ipynb.)
Application.Visible = 1Knew Ballmer let the company down but didn't think it was that far.