Open XML is an open ECMA 376 standard and is also approved as the ISO/IEC 29500 standard that defines a set of XML schemas for representing spreadsheets, charts, presentations, and word processing documents. Microsoft Office 2007 and Microsoft Office 2010 all use Open XML as the default file format for rendering spreadsheets, documents, and presentations.
The Open XML file formats are useful for developers because they use an open standard and are based on well-known technologies: ZIP and XML.
The Open XML SDK 2.0 for Microsoft Office is built on top of the System.IO.Packaging API and provides strongly typed part classes to manipulate Open XML documents. The SDK also uses the .NET Framework Language-Integrated Query (LINQ) technology to provide strongly typed object access to the XML content inside the parts of Open XML documents.
In the case of Microsoft Dynamics GP 2010, the assembly enables developers to easily read-from and write-to Microsoft Word documents using their favorite language in Microsoft Visual Studio. The following image depicts the assembly in the Global Assembly Cache (GAC).
The following C# console application demonstrates how to use OpenXML to add a new table to the end of a document (similar to the text added in the “terms and conditions” article).
The above example shows how simple it is to:
1) Crack open a word document.
2) Append a table to the end with specific properties.
3) Insert some ad-hoc text into the table.
The major advantage is the strongly typed interface to office document. You don’t need COM interoperability to manipulate any document.
You can download the sample project at the bottom of this article.
NewTableAdhocText.zip - C# command line application to demonstrate adding a table at the end of a Word Document.
Until next post!
Mariano Gomez, MVP
Maximum Global Business, LLC