Introduction to Open XML SDK 2.0
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in D:\Hosting\3681091\html\blog\wp-content\plugins\digg-digg\dd.class.php on line 759
Warning: file_get_contents(http://feeds.delicious.com/v2/json/urlinfo/data?url=http%3A%2F%2Fwww.devtheweb.net%2Fblog%2F2010%2F01%2F11%2Fintroduction-to-open-xml-sdk-2-0%2F) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in D:\Hosting\3681091\html\blog\wp-content\plugins\digg-digg\dd.class.php on line 759
Currently, I work with Open XML SDK 2.0 and in this post, I’ll try to explain simple introduction to it:
What is Open XML and Open XML SDK?
Open XML is an open standard that defines a set of XML schemas for representing spreadsheets, presentations, charts and word processing documents. Microsoft Office 2007 applications (Word, Excel and PowerPoint) use the Open XML as the default file format. The Open XML file formats are based on ZIP and XML.
The Open XML SDK 2.0 provides classes to manipulate Open XML documents. The Open XML SDK 2.0 uses the LINQ (Language-Integrated Query) technology to provide strongly typed object access to the XML content inside the parts of the Open XML documents.
Download and Install
You can download Open XML SDK 2.0 HERE.
System Requirements:
- OS: Windows 7; Windows Server 2003 SP 2; Windows Server 2008 R2; Windows Server 2008 SP 2; Windows Vista SP 2; Windows XP SP 3
- .NET Framework version 3.5 SP1
- At least 300 MB available disk space
Using the Open XML API 2.0 in Visual Studio 2008 Project
To use the API in your Visual Studio project, all you need to do is to add Reference to DocumentFormat.OpenXml:
In Solution Explorer, right-click References and select Add Reference.
In the dialog box, select .NET tab and select DocumentFormat.OpenXml option and then click OK.
Read Docx’s Text
It’s very easy to read the text of Word 2007 Document file, here’s an example:
using System.IO;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
//t local variables
WordprocessingDocument doc;
string result = “”;
try
{
//t load the .docx document
doc = WordprocessingDocument.Open(stringForFilePath, false);
result = (doc.MainDocumentPart.Document).Body.InnerText;
}
catch (Exception ex)
{
//t handle the exception
}
return result;
Conclusion
At first look it seems to be easy to work with the Open XML 2.0 SDK, it’s easy to install use in Visual Studio 2008. I created a simple program that loads text from docx file:

You can download it HERE.



One Comments to “Introduction to Open XML SDK 2.0”
I agree with you that the SDK has huge potential (and the guys at Microsoft are still working hard to improve it prior to its formal release alongside Office 2010).
However, using the SDK with Excel documents, I found that we developers are still required to implement many of the low-level details ourselves. I wrote about my experiences in an article that was just published on the OpenXMLDeveloper website: http://openxmldeveloper.org/articles/7937.aspx