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. Figure 1. Folder and file structure for a Word 2007 document
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
|
- 1/19/2012
- _1316018019
I thank u for this very useful video and written example.
good job.
how ever i need more. and i need your help because I've been searching the net for quit some time and can't find the answer.
I am using the open XML to generate a power point through code.
this presentation needs to contain a web browser and it has a button click event that populate the .navigate property.
the URL to the navigate property needs to be passed as a parameter.
what i did so far is to create a .PPTM file with a web browser control, button and some code behind that get a fixed URL (at the moment).
opened it via Productivity tool and decoded it. copy/paste to a c# class project in order to create the .PPTM file through code.
it works (more or less) so far, now i thought i could replace the Binary part that represent the code behind, but, I can't seem to find how you, at Microsoft, made this hex string.
Is there a way to do it.
can u please answer this one.
thanks, Yakov.
- 4/12/2011
- Yakov_YayaSoft.co.il
- 4/12/2011
- Yakov_YayaSoft.co.il
There were numerous errors in the xml code. You can find the errors by trying to load them into Internet Explorer. For example, the following two lines from document.xml can be fixed by moving the "m=" from the beginning of the second line to the end of the first line. So this:
officeDocument/2006/relationships" xmlns:
m="http://schemas.microsoft.com/office/omml/
...becomes this:
officeDocument/2006/relationships" xmlns:m=
"http://schemas.microsoft.com/office/omml/
In app.xml, consider this line:
extended-properties"xmlns:vt="http://schemas
This can be fixed by adding a space between the quote and the xmlns like this:
extended-properties" xmlns:vt="http://schemas
I strongly urge the writers to correct the errors, especially since this article is the first link in "Open XML Format SDK 2.0: Getting Started Best Practices"
- 4/5/2011
- Gamewriter
How can I in a easy way open a xml file, put nodes in a word template document, and save this dokument as a complete document.?
Mvh Tor Ystad Norway
- 3/4/2011
- torybennybassikova
- 9/15/2009
- SunilK
- 11/15/2009
- Thomas Lee
If I want to add Images or other objects in my document, where Images are stored in the document structure?
Thanks..
tfl - 15 11 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
- 9/14/2007
- Dave Bhavesh
- 11/15/2009
- Thomas Lee
Hi,
Where can I find code for Find & Replace in Word 2007?
Thanks.
tfl - 15 11 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
- 7/18/2007
- HemantPune
- 11/15/2009
- Thomas Lee
This looks like the most likely method to get all of the features that I want. Anybody know of any existing class or module
that will ease this process?
- 4/9/2009
- gmaddock
Note:
Important:
