Why won't my header show in MS Word using OOXML & Word JS API - ms-word

Trying to use Visual Studio 2017 to do this: Why is the header not showing in MS WORD? I tried to simplified from a real dotx document that was saved as XML. I managed to make it work with plain body text and even floating images in the body. But before I could work on images in header/footer, I am trying to test it with plain text in the header, but I just can't seem to figure out how to make it work. Thank you! See full XML script below:
<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/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="256">
<pkg:xmlData>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header1.xml"/>
<Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header2.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:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" >
<w:sectPr>
<w:headerReference r:id="rId6" w:type="first"/>
<w:headerReference r:id="rId7" w:type="default"/>
</w:sectPr>
<w:body>
<w:p>
<w:r>
<w:rPr>
<w:noProof/>
</w:rPr>
<w:t>testing 193</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name="/word/header1.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml">
<pkg:xmlData>
<w:hdr 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:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
<w:p>
<w:pPr>
<w:pStyle w:val="Header"/>
</w:pPr>
<w:r>
<w:t>helo this is first header</w:t>
</w:r>
</w:p>
</w:hdr>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name="/word/header2.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml">
<pkg:xmlData>
<w:hdr 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:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
<w:p>
<w:pPr>
<w:pStyle w:val="Header"/>
</w:pPr>
<w:r>
<w:t>helo this is default header</w:t>
</w:r>
</w:p>
</w:hdr>
</pkg:xmlData>
</pkg:part>
</pkg:package>

Related

Insert a content control with OOXML

The docs recommend the following way to add a content control:
<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" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" >
<w:body>
<w:p/>
<w:sdt>
<w:sdtPr>
<w:alias w:val="MyContentControlTitle"/>
<w:id w:val="1382295294"/>
<w15:appearance w15:val="hidden"/>
<w:showingPlcHdr/>
</w:sdtPr>
<w:sdtContent>
<w:p>
<w:r>
<w:t>[This text is inside a content control that has its container hidden. You can bind to a content control to add or interact with content at a specified location in the document.]</w:t>
</w:r>
</w:p>
</w:sdtContent>
</w:sdt>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>
But if one looks closely, the content control is added inside a paragraph (<w:p>):
<w:sdtContent>
<w:p>
<w:r>
<w:t>[This text is inside a content control that has its container hidden. You can bind to a content control to add or interact with content at a specified location in the document.]</w:t>
</w:r>
</w:p>
</w:sdtContent>
Is there a way I can prevent adding it inside the paragraph and make it inline? Just removing the <w:p> tag doesn't work somehow. Also, I am familiar with the Word API for adding content controls. My scenario is such that I have to produce and OOXML and then insert in into the document.
If you remove the <w:p> and </w:p> from inside the <w:sdtContent> element, then you have to wrap the <w:sdt> element in a <w:p> element, like this, otherwise Word will not recognize the content:
<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" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" >
<w:body>
<w:p/>
<w:p>
<w:sdt>
<w:sdtPr>
<w:alias w:val="MyContentControlTitle"/>
<w:id w:val="1382295294"/>
<w15:appearance w15:val="hidden"/>
<w:showingPlcHdr/>
</w:sdtPr>
<w:sdtContent>
<w:r>
<w:t>[This text is inside a content control that has its container hidden. You can bind to a content control to add or interact with content at a specified location in the document.]</w:t>
</w:r>
</w:sdtContent>
</w:sdt>
</w:p>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>
Viewed in Word, in "your" encoding style, the paragraph mark appears inside the content control. With the above encoding, it appears outside the content control, and that means that it is possible to insert content between the end of the control and the end of paragraph.

How to change page number of a Word Docx

I have a generated word document (docx) and want to change the page number afterwards, in a way that it starts at number X. The page number is included in the footer of the word document. Where in the XML files do I need to apply this change?
I have changed a document to start at number 4 and looked at the XML code. The element <w:pgNumType w:start="4"/> was added. But if I only add this part manually to the XML, the document is broken.
document.xml content before adding "start with number 4":
<w:sectPr w:rsidR="00C17A11" w:rsidRPr="00CD0C83" w:rsidSect="00A86D42">
<w:headerReference r:id="rId8" w:type="even"/>
<w:headerReference r:id="rId9" w:type="default"/>
<w:footerReference r:id="rId10" w:type="even"/>
<w:footerReference r:id="rId11" w:type="default"/>
<w:headerReference r:id="rId12" w:type="first"/>
<w:footerReference r:id="rId13" w:type="first"/>
<w:pgSz w:h="16838" w:w="11906"/>
<w:pgMar w:bottom="851" w:footer="567" w:gutter="0" w:header="851" w:left="1304" w:right="567" w:top="828"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
And after adding "start with number 4":
<w:sectPr w:rsidR="00C17A11" w:rsidRPr="00CD0C83" w:rsidSect="00CA253E">
<w:headerReference w:type="default" r:id="rId8"/>
<w:footerReference w:type="default" r:id="rId9"/>
<w:pgSz w:w="11906" w:h="16838"/>
<w:pgMar w:top="828" w:right="567" w:bottom="851" w:left="1304" w:header="851" w:footer="567" w:gutter="0"/>
<w:pgNumType w:start="4"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
As Josch mentioned you are doing everything right. There is nothing more to be added to the document.
I have created an empty document with 4 pages in Word and then unpacked the contents of my .wordx file.
Here is my document.xml file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" 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:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" 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" mc:Ignorable="w14 w15 w16se wp14">
<w:body>
<w:p w:rsidR="00ED7F18" w:rsidRDefault="00ED7F18">
<w:r>
<w:br w:type="page"/>
</w:r>
</w:p>
<w:p w:rsidR="00ED7F18" w:rsidRDefault="00ED7F18">
<w:r>
<w:lastRenderedPageBreak/>
<w:br w:type="page"/>
</w:r>
</w:p>
<w:p w:rsidR="00ED7F18" w:rsidRDefault="00ED7F18">
<w:r>
<w:lastRenderedPageBreak/>
<w:br w:type="page"/>
</w:r>
</w:p>
<w:p w:rsidR="0070592A" w:rsidRDefault="00ED7F18"/>
<w:sectPr w:rsidR="0070592A" w:rsidSect="00ED7F18">
<w:headerReference w:type="even" r:id="rId6"/>
<w:headerReference w:type="default" r:id="rId7"/>
<w:footerReference w:type="even" r:id="rId8"/>
<w:footerReference w:type="default" r:id="rId9"/>
<w:headerReference w:type="first" r:id="rId10"/>
<w:footerReference w:type="first" r:id="rId11"/>
<w:pgSz w:w="11906" w:h="16838"/>
<w:pgMar w:top="1417" w:right="1417" w:bottom="1134" w:left="1417" w:header="708" w:footer="708" w:gutter="0"/>
<w:pgNumType w:start="4"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
</w:document>
Changing the following line
<w:pgNumType w:start="4"/>
to
<w:pgNumType w:start="5"/>
and then zipping back all the contents does the thing.
You are probably zipping back the contents together with the folder they are in.
Please make sure that the zip file has exactly the following folders/files.
_rels
docProps
word
[Content_Types].xml

How can I create a Toc(Table of Content) for a document in Word using office.js?

How can I create a Toc(Table of Content) for a document in Word using office.js? I have look through the help doc on github, but find nothing about this. Please help me. Thank you very much.
Table of Contents is currently not a supported object of the Word JS API.
Make sure to add this idea to our user voice channel
https://officespdev.uservoice.com/forums/224641-feature-requests-and-feedback/category/163566-add-in-word
I am experiment TOC in Word JS API[preview]
till now i had created some sort of TOC look in Word JS API with help of XML[insertOoxml]
Word.run(async function (context) {
const currentDoc = context.document;
const body = currentDoc.body;
const paragraphs = currentDoc.body.paragraphs.load('items');
const headers = [];
const uniqueStr = new Date().getTime();
let insertion = '';
await context.sync();
for (let i = 0; i < paragraphs.items.length; i++) {
// we can use outlineLevel 1,2,3
if (
paragraphs.items[i].styleBuiltIn === 'Heading1' ||
paragraphs.items[i].styleBuiltIn === 'Heading2' ||
paragraphs.items[i].styleBuiltIn === 'Heading3'
) {
headers.push(paragraphs.items[i]);
}
}
const xValues = headers.map(function (o) {
return o.outlineLevel;
});
const xMax = Math.max.apply(null, xValues);
const xMin = Math.min.apply(null, xValues);
console.log(headers);
headers.map(function (item, i) {
console.log(item.outlineLevel);
const bookmarkName = `_Toc${item.outlineLevel + item._Id + uniqueStr}`;
insertion += `<w:p w:rsidR='00000000' w:rsidRDefault='0043114D'>
<w:pPr>
<w:pStyle w:val='TOC${item.outlineLevel}'/>
<w:tabs>
<w:tab w:val='right' w:leader='dot' w:pos='9016'/>
<w:tab w:val="left" w:pos="9016" w:leader='dot'/>
</w:tabs>
<w:rPr>
<w:rFonts w:eastAsiaTheme='minorEastAsia' w:cs='Latha'/>
<w:noProof/>
</w:rPr>
</w:pPr>
${
i === 0
? `<w:r>
<w:fldChar w:fldCharType='begin'/>
</w:r>
<w:r>
<w:rPr>
<w:noProof />
<w:webHidden />
</w:rPr>
<w:instrText xml:space='preserve'> TOC \\o "${xMin}-${xMax}" \\h \\z \\u </w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType='separate'/>
</w:r>`
: `<w:r><w:rPr>
<w:noProof />
<w:webHidden />
</w:rPr></w:r>`
}
<w:p w:rsidR='00000000' w:rsidRDefault='0043114D'>
<w:r>
<w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
<w:instrText xml:space="preserve"> PAGEREF ${bookmarkName} \\h </w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
<w:noProof/>
</w:rPr>
<w:t>${item.text.toString()}</w:t>
</w:r>
<w:r>
<w:tab />
</w:r>
<w:r>
<w:rPr>
<w:noProof />
<w:webHidden />
<w:spacing w:line='50' w:lineRule='auto'/>
</w:rPr>
<w:fldChar w:fldCharType='separate' />
</w:r>
<w:r>
<w:rPr>
<w:noProof />
<w:webHidden />
</w:rPr>
<w:t xml:space="preserve"> 1 </w:t>
</w:r>
<w:r>
<w:fldChar w:fldCharType="end"/>
</w:r>
</w:p>
</w:p>`;
const insertRange: Word.Range = item.getRange();
insertRange.insertBookmark(bookmarkName);
});
body.insertOoxml(
`<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:sdt>
<w:sdtPr>
<w:id w:val='${uniqueStr}' />
<w:docPartObj>
<w:docPartGallery w:val='Table of Contents' />
<w:docPartUnique />
</w:docPartObj>
</w:sdtPr>
<w:sdtEndPr>
<w:rPr>
<w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi" w:cstheme="minorBidi" />
<w:b />
<w:bCs />
<w:noProof />
<w:color w:val="auto" />
<w:sz w:val="22" />
<w:szCs w:val="22" />
</w:rPr>
</w:sdtEndPr>
<w:sdtContent>
<w:p w:rsidR="00095C65" w:rsidRDefault="00095C65">
<w:pPr>
<w:pStyle w:val='TOCHeading'/>
<w:b />
<w:color w:val="2E74B5" w:themeColor="accent1" w:themeShade="BF" />
<w:sz w:val="30" />
<w:szCs w:val="30" />
</w:pPr>
<w:r>
<w:t>Contents</w:t>
</w:r>
</w:p>
${insertion}
</w:sdtContent>
</w:sdt>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>`,
Word.InsertLocation.start
);
await context.sync();
console.log('xml added at the start of the document body.');
}).catch(OfficeAddinFacade.errorHandler);
now i want page number in dynamic way where Header[1,2,3] is present
someone can help me this

Open xml headers not being set with Office Addin

I'm going through this, pretty good, document (http://dev.office.com/docs/add-ins/word/create-better-add-ins-for-word-with-office-open-xml?product=word) to understand OOXML better and to use it in a Word Addin.
To test my created OOXM, I use this sample: http://dev.office.com/code-samples-detail/5789.
Simple stuff works, but when I try to set the headers of the document it doesn't seem to work.
Here's the OOXML snippet:
<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/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="256">
<pkg:xmlData>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header2.xml"/>
<Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header1.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:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" 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:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" 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" mc:Ignorable="w14 w15 w16se wp14">
<w:body>
<w:p w:rsidR="003F424D" w:rsidRDefault="003F424D">
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
<w:r>
<w:br w:type="page"/>
</w:r>
</w:p>
<w:p w:rsidR="00C24E89" w:rsidRDefault="009F0685"/>
<w:sectPr w:rsidR="00C24E89" w:rsidSect="003F424D">
<w:headerReference w:type="default" r:id="rId6"/>
<w:headerReference w:type="first" r:id="rId7"/>
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:titlePg/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
<pkg:xmlData>
<w:endnotes xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" 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:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" 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" mc:Ignorable="w14 w15 w16se wp14">
<w:endnote w:type="separator" w:id="-1">
<w:p w:rsidR="009F0685" w:rsidRDefault="009F0685" w:rsidP="003F424D">
<w:pPr>
<w:spacing w:after="0" w:line="240" w:lineRule="auto"/>
</w:pPr>
<w:r>
<w:separator/>
</w:r>
</w:p>
</w:endnote>
<w:endnote w:type="continuationSeparator" w:id="0">
<w:p w:rsidR="009F0685" w:rsidRDefault="009F0685" w:rsidP="003F424D">
<w:pPr>
<w:spacing w:after="0" w:line="240" w:lineRule="auto"/>
</w:pPr>
<w:r>
<w:continuationSeparator/>
</w:r>
</w:p>
</w:endnote>
</w:endnotes>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name="/word/header1.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml">
<pkg:xmlData>
<w:hdr xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" 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:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" 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" mc:Ignorable="w14 w15 w16se wp14">
<w:p w:rsidR="003F424D" w:rsidRPr="003F424D" w:rsidRDefault="003F424D">
<w:pPr>
<w:pStyle w:val="Koptekst"/>
<w:rPr>
<w:lang w:val="nl-NL"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="nl-NL"/>
</w:rPr>
<w:t>OtherPagesHeader</w:t>
</w:r>
</w:p>
</w:hdr>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name="/word/header2.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml">
<pkg:xmlData>
<w:hdr xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" 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:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" 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" mc:Ignorable="w14 w15 w16se wp14">
<w:p w:rsidR="003F424D" w:rsidRPr="003F424D" w:rsidRDefault="003F424D">
<w:pPr>
<w:pStyle w:val="Koptekst"/>
<w:rPr>
<w:lang w:val="nl-NL"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="nl-NL"/>
</w:rPr>
<w:t>FirstPageHeader</w:t>
</w:r>
</w:p>
</w:hdr>
</pkg:xmlData>
</pkg:part>
<pkg:xmlData>
<w:fonts xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 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:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" mc:Ignorable="w14 w15 w16se">
<w:font w:name="Calibri">
<w:panose1 w:val="020F0502020204030204"/>
<w:charset w:val="00"/>
<w:family w:val="swiss"/>
<w:pitch w:val="variable"/>
<w:sig w:usb0="E0002AFF" w:usb1="C000247B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
</w:font>
<w:font w:name="Times New Roman">
<w:panose1 w:val="02020603050405020304"/>
<w:charset w:val="00"/>
<w:family w:val="roman"/>
<w:pitch w:val="variable"/>
<w:sig w:usb0="E0002EFF" w:usb1="C000785B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
</w:font>
<w:font w:name="Calibri Light">
<w:panose1 w:val="020F0302020204030204"/>
<w:charset w:val="00"/>
<w:family w:val="swiss"/>
<w:pitch w:val="variable"/>
<w:sig w:usb0="E0002AFF" w:usb1="C000247B" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
</w:font>
</w:fonts>
</pkg:xmlData>
</pkg:part>
I'm a bit confused on what I'm missing here to make this work.
upon further investigation, you cannot modify the header visibility with OOXML. the good news is that we are going to include a few properties at the section level to enable showing primary and even-page headers.

Is this correct Open Office XML?

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<?mso-application progid="Word.Document"?>
<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/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="256">
<pkg:xmlData>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.png" />
</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 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:rsidR="00AE3E50" w:rsidRDefault="00DE2072">
<w:r>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="2194560" cy="1463040" />
<wp:docPr id="1" name="My Video" />
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks noChangeAspect="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
</wp:cNvGraphicFramePr>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:nvPicPr>
<pic:cNvPr id="1" name="" />
<pic:cNvPicPr />
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="rId2">
<a:extLst>
<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
<a14:useLocalDpi val="0" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" />
</a:ext>
<a:ext uri="{C809E66F-F1BF-436E-b5F7-EEA9579F0CBA}">
<wp15:webVideoPr embeddedHtml="<iframe width="800" height="600" src="http://www.youtube.com/embed/qk51u8-4uo4" frameborder="0" allowfullscreen></iframe>" w="800" h="600" xmlns:wp15="http://schemas.microsoft.com/office/word/2012/wordprocessingDrawing" />
</a:ext>
</a:extLst>
</a:blip>
<a:stretch>
<a:fillRect />
</a:stretch>
</pic:blipFill>
<pic:spPr>
<a:xfrm>
<a:off x="0" y="0" />
<a:ext cx="2194560" cy="1463040" />
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst />
</a:prstGeom>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
</w:r>
</w:p>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name="/word/media/image1.png" pkg:contentType="image/png" pkg:compression="store">
<pkg:binaryData>
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAHN6w8ZAAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAGUExURQAAAAAAAKVnuc8AAAACdFJOU/8A5bcwSgAAAAlwSFlzAAAOxAAADsQBlSsO
GwAAAAxJREFUGFdjYBgYAAAAeAABoRR6NAAAAABJRU5ErkJggg==
</pkg:binaryData>
</pkg:part>
</pkg:package>
I'm not sure whether above one is correct or not but it keeps giving me error "Invalid format" while adding to MS word using programming".
The error is
Error Message: The format of the specified data object is invalid.
Error Code: 2006
Here is click event for the buttonw which is inserting code...
Office.context.document.setSelectedDataAsync
(
xmlCode,
{ coercionType: "ooxml" },
function (result)
{
console.log("test");
}
);
variable xmlCode is consists of ooxml code as string data.
It's solved now...
The mistake that I was doing is, I have placed the ooxml code inside a <textarea> html element. So while it was being rendered inside browser, the html encoded iframe code was converted into HTML tags which was causing issue. I updated my code, removed ooxml code from <textarea> and placed it directly as string to variable and the problem was solved.
Now, I'm able to embed video using office.js
I'm not entirely sure that the OOXML data should be a string.
Writing data from apps to Office documents suggests that you should be using a CustomXmlNode object:
In the event that you cannot insert content through any of the above methods, and if you are in Word 2013, you can directly alter the structure of the document by inserting OOXML nodes. This gets complicated fast—refer to the Apps for Office CustomXmlNode APIs for more information.
(I especially love "this gets complicated fast"...sure makes me excited to use that API!)