Example
link - docs.microsoft.com/en-us/office/dev/add-ins/word/create-better-add-ins-for-word-with-office-open-xml
When you grab the Office Open XML for the formatted text using getSelectedDataAsync or getOoxml you see a large amount of markup.
That markup includes a package element that represents an entire document, which contains several parts (commonly referred to as document parts or, in the Office Open XML, as package parts),
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
pkg:name = _rels/.rels
Defines relationships between the top-level parts of the package (these are typically the document properties, thumbnail (if any), and main document body).
Some of the content in this part is always required in your markup because you need to define the relationship of the main document part (where your content resides) to the document package.
Remember that every document part must have a relationship defined in the package and those relationships appear in the .rels files.
So you should see all of them listed in either .rels, document.xml.rels, or a content-specific .rels file.
Remove the relationships (that is, the Relationship tag) for any parts that you completely remove from the package.
Including a part without a corresponding relationship, will result in an error.
Excluding a part that has a relationship in the package, will result in an error.
<pkg:part pkg:name="/_rels/.rels"
pkg:contentType="application/vnd.openxmlformats-package.relationships+xml"
pkg:padding="512">
<pkg:xmlData>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
Target="word/document.xml"/>
</Relationships>
</pkg:xmlData>
</pkg:part>
pkg:name = word/document.xml
Is the content in the main body of the document.
Is the primary document part where you place your content.
<pkg:part pkg:name="word/document.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
</pkg:part>
Defines relationships for additional parts required by the document.xml (main body) part, if any.
<pkg:part pkg:name="/word/_rels/document.xml.rels"
pkg:contentType="application/vnd.openxmlformats-package.relationships+xml"
pkg:padding="256">
</pkg:part>
<pkg:part pkg:name="/word/footnotes.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml">
</pkg:part>
<pkg:part pkg:name="/word/endnotes.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml">
</pkg:part>
<pkg:part pkg:name="/word/media/image1.emf"
pkg:contentType="image/x-emf">
</pkg:part>
<pkg:part pkg:name="/word/numbering.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml">
</pkg:part>
<pkg:part pkg:name="/word/styles.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml">
</pkg:part>
Ignored by the Set method
<pkg:part pkg:name="/word/theme/theme1.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.theme+xml">
</pkg:part>
Ignored by the Set method
<pkg:part pkg:name="/word/settings.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml">
</pkg:part>
Ignored by the Set method
<pkg:part pkg:name="/word/webSettings.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml">
</pkg:part>
Ignored by the Set method
<pkg:part pkg:name="/word/fontTable.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml">
</pkg:part>
Ignored by the Set method
<pkg:part pkg:name="/docProps/thumbnail.emf"
</pkg:part>
Ignored by the Set method
<pkg:part pkg:name="/docProps/core.xml"
</pkg:part>
Ignored by the Set method
<pkg:part pkg:name="/docProps/app.xml"
</pkg:part>
</pkg:package>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
<pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512">
<pkg:xmlData>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
</Relationships>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
<pkg:xmlData>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" >
<w:body>
<w:p>
<w:pPr>
<w:spacing w:before="360" w:after="0" w:line="480" w:lineRule="auto"/>
<w:rPr>
<w:color w:val="70AD47" w:themeColor="accent6"/>
<w:sz w:val="28"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:color w:val="70AD47" w:themeColor="accent6"/>
<w:sz w:val="28"/>
</w:rPr>
<w:t>This text has formatting directly applied to achieve its font size, color, line spacing, and paragraph spacing.</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>
function writeContent() {
var myOOXMLRequest = new XMLHttpRequest();
var myXML;
myOOXMLRequest.open('GET', 'yourXMLfilename', false);
myOOXMLRequest.send();
if (myOOXMLRequest.status === 200) {
myXML = myOOXMLRequest.responseText;
}
Office.context.document.setSelectedDataAsync(myXML, { coercionType: 'ooxml' });
}
This shows the document.xml part, which includes our sample formatted text content before editing.
The opening w:document tag includes several namespace ( xmlns ) listings. Many of those namespaces refer to specific types of content and you only need them if they're relevant to your content.
Notice that the prefix for the tags throughout a document part refers back to the namespaces. In this example, the only prefix used in the tags throughout the document.xml part is w:, so the only namespace that we need to leave in the opening w:document tag is xmlns:w.
If you remove the xmlns:mc namespace, you must also remove the mc:Ignorable attribute that precedes the namespace listings.
Inside the opening body tag, you see a paragraph tag ( w:p ), which includes our sample content for this example.
The w:pPr tag includes properties for directly-applied paragraph formatting, such as space before or after the paragraph, paragraph alignment, or indents. (Direct formatting refers to attributes that you apply individually to content rather than as part of a style.) This tag also includes direct font formatting that's applied to the entire paragraph, in a nested w:rPr (run properties) tag, which contains the font color and size set in our sample.
paragraph and line spacing, as well some section formatting properties shown in the preceding markup, are specified in twips (one-twentieth of a point). Depending on the types of content you work with in Office Open XML, you may see several additional units of measure,
Within a paragraph, any content with like properties is included in a run ( w:r ), such as is the case with the sample text. Each time there's a change in formatting or content type, a new run starts. (That is, if just one word in the sample text was bold, it would be separated into its own run.) In this example, the content includes just the one text run.
Notice that, because the formatting included in this sample is font formatting (that is, formatting that can be applied to as little as one character), it also appears in the properties for the individual run.
Also notice the tags for the hidden "_GoBack" bookmark (w:bookmarkStart and w:bookmarkEnd ), which appear in Word documents by default. You can always delete the start and end tags for the GoBack bookmark from your markup.
The last piece of the document body is the w:sectPr tag, or section properties. This tag includes settings such as margins and page orientation.
The content you insert using setSelectedDataAsync will take on the active section properties in the destination document by default. So, unless your content includes a section break (in which case you'll see more than one w:sectPr tag), you can delete this tag.
<pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
<pkg:xmlData>
<w:document mc:Ignorable="w14 w15 wp14" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
<w:body>
<w:p>
<w:pPr>
<w:spacing w:before="360" w:after="0" w:line="480" w:lineRule="auto"/>
<w:rPr>
<w:color w:val="70AD47" w:themeColor="accent6"/>
<w:sz w:val="28"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:color w:val="70AD47" w:themeColor="accent6"/>
<w:sz w:val="28"/>
</w:rPr>
<w:t>This text has formatting directly applied to achieve its font size, color, line spacing, and paragraph spacing.</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:p/>
<w:sectPr>
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
<w:cols w:space="720"/>
</w:sectPr>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
Working with Images
The markup for an image includes a reference to at least one part that includes the binary data to describe your image.
<a:blip r:embed="rId4" cstate="print">
The reference to the image is included in the a:blip tag.
This is using an explicit relationship reference ( r:embed="rID4" ) and that related part is required in order to render the image, if you don't include the binary data in your Office Open XML package, you will get an error.
The relationships namespace (r) must be placed at the start of document.xml (and not just before it is used).
<Relationship Id=\"rId7\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\" Target=\"media/image1.emf\
<pkg:part pkg:name=\"/word/media/image1.emf\" pkg:contentType=\"image/x-emf\">
<pkg:binaryData>
base64string
</pkg:binaryData>
</pkg:part>
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext