Building Word 2007 Documents Using Office Open XML Formats
Erika Ehrli, Brian Jones, Microsoft Corporation
Applies to: 2007 Microsoft Office System, Microsoft Office Word 2007, Office Open XML Formats
The Office Open XML Formats are based on XML and ZIP archive technologies. The new file format in Microsoft Office Word 2007 divides the file into document parts, each of which defines a part of the overall contents of the file. You can easily create, change, add, or delete data in a Word 2007 file programmatically or manually.
To illustrate how document parts, content type items, and relationship items work together, this section walks through the process of building a Word XML format document in Word 2007.
To create a Word 2007 document that contains content type and relationship items, you need to create a root folder that contains a specific folder and file structure, as shown in Figure 1.
After you create all folders and files, the next section walks you through adding the required XML code to each document part.
Creating the Document Properties
First, you need to create two XML files for the document properties:
Creating the Document
Next, you need to create an XML file for the document part. This is the only required part in the new Word XML format.
Creating a Relationship
Next, you need to create a relationship to this part. This relationship is documented in the root _relsfolder, which means that the relationship is off the root (or start part) of the package. To create the relationship:
Defining the Content Type
Next, you need to define the content type of this file.
Creating the Package
Finally, you can put these files into a ZIP package to create a valid Word 2007 document:
Now, you can open this file in Word 2007 and see the contents of the package.
The file format in Word 2007 consists of a compressed ZIP file, called a package. This package holds all of the content that is contained within the document. You can extract and open the files in the package to reveal component parts that give you access to the structures that compose the file. Figure 2 shows the file structure of a sample Word 2007 document.
Figure 2. Hierarchical file structure of a typical Word 2007 document
To understand the structure of a Word 2007 document, you must understand the three major components of the new file format:
You can replace and add entire document parts to change the content, properties, or formatting of Word 2007 documents. For more information about the Word 2007 file format, read the article Walkthrough: Word 2007 XML Format.
You can also build Word 2007 documents programmatically by using the Microsoft WinFX System.IO.Packaging class. For example, by using the Microsoft WinFX System.IO.Packaging class, you can create a document part with the PackagePart.CreatePart method. For more information about PackageParts, see the PackagePart Class reference documentation in the Microsoft Windows SDK.
Video Length: 00:08:24
File Size: 9.55 MB
File Type: WMV file