OpenXML and PowerShell
While preparing for this months UK user group talk on PowerShell and Office I decided I wanted to include a look at working with the OpenXML format for Office documents that was introduced in Office 2007. These are the .docx and .xlsx versions of Word and Excel respectively.
When writing PowerShell in Practice (www.manning.com/siddaway) I included a small section on working with Word and Excel. This contained a bit on using OpenXML.
I’ve rebuilt my system to Windows 7 since those days so needed to re-install the OpenXML support. I went searching and found it on codeplex - http://powertools.codeplex.com/
The latest release is 1.1.1
Codeplex contains the source code. You will need Visual Studio and a copy of the OpenXML SDK to compile it. The link given on codeplex for the SDK is wrong. You need to use these links
There is a problem in that version 1 of the SDK won’t install on Windows 7 and if you want to use the pre-compiled binaries instead of compiling your own they are created with version 1. This causes errors when SDK 2.0 is used on Windows 7 (with Office 2010).
A couple of code changes are needed if you want to compile the code against version 2 of the SDK – see http://powertools.codeplex.com/workitem/5057 for the code changes
This seems to work OK and a way to load the snapin as a module was given here http://msmvps.com/blogs/richardsiddaway/archive/2011/06/19/snapins-to-modules.aspx
I’ll be doing some more testing and will report any issues. So far all of my old openxml scripts just work.
If anyone wants a copy of the binaries just leave a comment and I’ll post them