views:

598

answers:

1

Hi,

I need to know how I get the stream of the headers and footers of a WordprocessingDocument. I get the MainDocument by the MainDocumentPart of a WordprocessingDocument. Do you know how I get the header? I tried to use the method GetPartsOfType but it returned null.

Greets

Sebastian

A: 

Obtaining the header and the footer is a little bit more complex, than getting a document part.

As it is described here (a quite good sorce of information), there can be many headers and footers within the document and even within a section.

So what you have to do is to open that main document part, identify the w:headerReference elemnt inside the section (w:sectPr) element. This headerReference (or footer of course) contains information about the header kind (first page, odd, even pages, or general), and also a reference id (e.g. "rId6"). Based on the reference id, you can look up the header/footer references (GetRelationship()) and with that you can find the header/footer part.

Note: interestingly the relationship type of the headers/footers was "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" instead of "http://schemas.openxmlformats.org/wordprocessingml/2006/header" which is in the specification, but since you anyway should lookup the header/footer by reference id, and not reference type, this is not a problem actually.

Gaspar Nagy