Hi All,

I'm using VB.net to create a batch of word documents using the Microsoft Office OpenXML SDK.

The documents are made up of a header and the main body which is made up of a table. I can sucessfully create the table in the main body. The issue is that the header does not appear in the document when I open it in word.

I've ran the document through the Open XML SDK 2.0 Productivity tool and it gives no validation errors and I can see the header.XML file and the refereneces to it in the the rel files and Content_Types. All the xml appears properly formed. I took a copy of one of the documents and changed the extension to .zip and looked at the xml in there as well.


Here is the header.xml file:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?> 
<w:hdr xmlns:ve="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: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:wne="http://schemas.microsoft.com/office/word/2006/wordml">
  <w:p w:rsidR="00D029D2" w:rsidRDefault="00D029D2">
  <w:pPr>
  <w:pStyle w:val="Header" /> 
  </w:pPr>
  </w:p>
  <w:p>
  <w:bookmarkStart w:name="Field_Logo" w:id="1" /> 
  <w:r>
  <w:t>Logo</w:t> 
  </w:r>
  <w:bookmarkEnd w:id="1" /> 
  </w:p>
  <w:p>
  <w:pPr>
  <w:pStyle w:val="Heading2" /> 
  </w:pPr>
  <w:bookmarkStart w:name="Field_Title" w:id="2" /> 
  <w:r>
  <w:t>Title</w:t> 
  </w:r>
  <w:bookmarkEnd w:id="2" /> 
  </w:p>
  <w:p>
  <w:bookmarkStart w:name="Field_Explanatory Statement" w:id="3" /> 
  <w:r>
  <w:t>Explanatory Statement</w:t> 
  </w:r>
  <w:bookmarkEnd w:id="3" /> 
  </w:p>
  </w:hdr>

Does anyone have any idea why it is not rendering in the document?

In my VB.Net code I'm creating a new word doc from scratch, importing a default header xml file and then appending the paragraphs to it.

Hi Guys,

The problem was to do with the fact that if you are creating a document from scratch, there are no section properties and therefore there is no reference to the header unless you explicitly add them.

This question has already been answered. Start a new discussion instead.