I need to retrieve Header/Footer parts from an OpenXML document in the order that they appear in the document.
The following:-
foreach (HeaderPart header in document.MainDocumentPart.HeaderParts)
{
...
}
-appears to iterate through the HeaderParts
in no particular order.
Can anyone explain how to order these correctly? Either by using OrderBy, or by accessing the HeaderParts
differently?
Edit: Examples
For example:-
In an example document I have several section breaks. Each section has a different header/footer:-
- Section 1 => Section 1 Footer
- Section 2 => Section 2 Footer
- Section 3 => Section 3 Footer
- Section 4 => Section 4 Footer
There are no "different first page" or "different odd/even" headers or footers in the document.
When I attempt to iterate over these footers using document.MainDocumentPart.FooterParts
, they do not appear in the order 1, 2, 3, 4. I have not been able to determine the logic behind the order which these footers appear in the sequence. I suspect that they are not ordered.
I need them in order.