Open XML SDK and Continuous Section breaks
There was a question the other day in the Open XML SDK forum about inserting Continuous section breaks. Inspecting a document.xml file, you’d think it would be as simple as adding a SectionType
child element to a SectionProperties
element associated with a paragraph’s properties, as can be seen in the following Word Open XML:
<w:p><w:pPr><w:sectPr w:rsidR=”0008038F” w:rsidSect=”00C26E80″>
<w:type w:val=”continuous”/>
<w:pgSz w:w=”11906″ w:h=”16838″/>
<w:pgMar w:gutter=”0″ w:footer=”708″ w:header=”708″ w:left=”1417″ w:bottom=”1134″ w:right=”1417″ w:top=”1417″/>
<w:cols w:space=”708″/><w:docGrid w:linePitch=”360″/>
</w:sectPr></w:pPr></w:p>
If only it were that simple! Word would open the document just fine, a section break was there… But it was always a Next Page section break.
I next inspected a manually generated document with continuous section breaks and noticed something unexpected: the SectionProperty
immediately following a continuous section break was also of type “continuous”, even though the break itself was a Next Page break!
Some testing revealed that, yes, indeed, the section break type of the following SectionProperties
determines the type of break for the preceding SectionProperties
.
After some intensive thought, I came to the conclusion that, as odd and unexpected as this seems, the behavior is correct. The settings of a section break always affect the text preceding the break, not the text following!
My next investigation involved how to force a continuous section break in the middle of a paragraph, which I’ll describe in my next post…