PowerTools for Open XML
One of the namespaces introduced in the .NET Framework 3.0 is System.IO.Packaging (in the WindowsBase assembly), which provides classes that support storage of multiple data objects in a single container, like a ZIP file. These data objects can be referenced in a hierarchical format, similar to the file system. This functionality can be used to open, read and manipulating the files based on the Open XML standard since the Open XML file format follows the same principle. A while back, I wrote a piece of code for a customer to use the classes in this namespace for setting the values for custom properties in Word 2007 documents and Excel 2007 spreadsheets. This wasn't hard but I had to use XPath queries and use the appropriate XML namespaces in order to find the elements I was trying to update.
We then had an initiative to create an SDK that provides strongly-typed part classes for use with the documents based on Open XML. This SDK was available in CTP mode until earlier this week when its first version was released. You can now download the Open XML Format SDK from the Download Center. This SDK relies on the functionality provided by the System.IO.Packaging namespace so it requires .NET Framework 3.0.
The Open XML Format SDK makes the life so much easier for the developers, but wait... we are not finished yet. Right after the release of the Open XML Format SDK, another open source project called "PowerTools for Open XML" was announced, which provides more than 30 PowerShell cmdlets to manipulate the Open XML files. So for example, there are cmdlets for manipulating the watermark, header and footer, style, etc. This means you can read and edit Open XML files on the server-side without using the Office object model and without a need for an Office 2007 license on the server machine. Here is a great screencast that includes some nice demos that show how you can use the PowerTools to go through a list of Word documents, add a watermark to all of them and make sure they all use the same text style. There is also another demo that performs a mail merge using a simple PowerShell script.
Video: PowerTools for Open XML Introduction
I remember that a few years back, I was working on a project where the customer decided to spend a considerable amount of cash on a document generation and rendering solution and the development team had to write a lot of code to populate the templates provided by the third-party solution. The integration and testing experience was quite painful too. It is great to see how the publication of Open XML as a standard and the development of great tools by Microsoft and the open source community has simplified the document generation process and I can clearly see how this will result in reduction of licensing and development costs.