File: sections.rst

package info (click to toggle)
python-docx 0.8.11%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,640 kB
  • sloc: xml: 25,311; python: 21,911; makefile: 168
file content (311 lines) | stat: -rw-r--r-- 10,642 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311

Sections
========

Word supports the notion of a *section*, having distinct page layout settings.
This is how, for example, a document can contain some pages in portrait layout
and others in landscape. Section breaks are implemented completely differently
from line, page, and column breaks. The former adds a ``<w:pPr><w:sectPr>``
element to the last paragraph in the new section. The latter inserts
a ``<w:br>`` element in a run.

The last section in a document is specified by a ``<w:sectPr>`` element
appearing as the last child of the ``<w:body>`` element. While this element
is optional, it appears that Word creates it for all files. Since most files
have only a single section, the most common case is where this is the only
``<w:sectPr>`` element.

Additional sections are specified by a ``w:p/w:pPr/w:sectPr`` element in the
last paragraph of the section. Any content in that paragraph is part of the
section defined by its ``<w:sectPr>`` element. The subsequent section begins
with the following paragraph.

When a section break is inserted using the Word UI, the following steps
occur:

1. The next-occurring ``<w:sectPr>`` element is copied and added to the
   current paragraph. (It would be interesting to see what happens when that
   paragraph already has a ``<w:sectPr>`` element.)
2. A new paragraph is inserted after the current paragraph. The text occuring
   after the cursor position is moved to the new paragraph.
3. The start-type (e.g. next page) of the next-occuring ``<w:sectPr>``
   element is changed to reflect the type chosen by the user from the UI.


Word behavior
-------------

* A paragraph containing a section break (<w:sectPr> element) does not
  produce a ¶ glyph in the Word UI.
* The section break indicator/double-line appears directly after the text of
  the paragraph in which the <w:sectPr> appears. If the section break
  paragraph has no text, the indicator line appears immediately after the
  paragraph mark of the prior paragraph.


Before and after analysis
~~~~~~~~~~~~~~~~~~~~~~~~~

.. highlight:: xml

Baseline document containing two paragraphs::

  <w:body>
    <w:p>
      <w:r>
        <w:t>Paragraph 1</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:r>
        <w:t>Paragraph 2</w:t>
      </w:r>
    </w:p>
    <w:sectPr>
      <w:pgSz w:w="12240" w:h="15840"/>
      <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800"
               w:header="720" w:footer="720" w:gutter="0"/>
      <w:cols w:space="720"/>
      <w:docGrid w:linePitch="360"/>
    </w:sectPr>
  </w:body>


Odd-page section inserted before paragraph mark in Paragraph 1::

  <w:body>
    <w:p>
      <w:pPr>
        <w:sectPr>
          <w:pgSz w:w="12240" w:h="15840"/>
          <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800"
                   w:header="720" w:footer="720" w:gutter="0"/>
          <w:cols w:space="720"/>
          <w:docGrid w:linePitch="360"/>
        </w:sectPr>
      </w:pPr>
      <w:r>
        <w:t>Paragraph 1</w:t>
      </w:r>
    </w:p>
    <w:p/>
    <w:p>
      <w:r>
        <w:t>Paragraph 2</w:t>
      </w:r>
    </w:p>
    <w:sectPr w:rsidR="00F039D0" w:rsidSect="006006E7">
      <w:type w:val="oddPage"/>
      <w:pgSz w:w="12240" w:h="15840"/>
      <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800"
               w:header="720" w:footer="720" w:gutter="0"/>
      <w:cols w:space="720"/>
      <w:docGrid w:linePitch="360"/>
    </w:sectPr>
  </w:body>

UI shows empty ¶ mark in first position of new next page. Section break
indicator appears directly after Paragraph 1 text, with no intervening
¶ mark.


Even-page section break inserted before first character in Paragraph 2::

  <w:body>
    <w:p>
      <w:r>
        <w:t>Paragraph 1</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:pPr>
        <w:sectPr>
          <w:type w:val="oddPage"/>
          <w:pgSz w:w="12240" w:h="15840"/>
          <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800"
                   w:header="720" w:footer="720" w:gutter="0"/>
          <w:cols w:space="720"/>
          <w:docGrid w:linePitch="360"/>
        </w:sectPr>
      </w:pPr>
    </w:p>
    <w:p>
      <w:r>
        <w:lastRenderedPageBreak/>
        <w:t>Paragraph 2</w:t>
      </w:r>
    </w:p>
    <w:sectPr>
      <w:type w:val="evenPage"/>
      <w:pgSz w:w="12240" w:h="15840"/>
      <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800"
               w:header="720" w:footer="720" w:gutter="0"/>
      <w:cols w:space="720"/>
      <w:docGrid w:linePitch="360"/>
    </w:sectPr>
  </w:body>


Enumerations
------------

WD_SECTION_START
~~~~~~~~~~~~~~~~

alias: **WD_SECTION**

`WdSectionStart Enumeration on MSDN`_

.. _WdSectionStart Enumeration on MSDN:
   http://msdn.microsoft.com/en-us/library/office/bb238171.aspx

CONTINUOUS (0)
    Continuous section break.

NEW_COLUMN (1)
    New column section break.

NEW_PAGE (2)
    New page section break.

EVEN_PAGE (3)
    Even pages section break.

ODD_PAGE (4)
    Odd pages section break.


WD_ORIENTATION
~~~~~~~~~~~~~~

alias: **WD_ORIENT**

`WdOrientation Enumeration on MSDN`_

.. _WdOrientation Enumeration on MSDN:
   http://msdn.microsoft.com/en-us/library/office/ff837902.aspx

LANDSCAPE (1)
    Landscape orientation.

PORTRAIT (0)
    Portrait orientation.


Schema excerpt
--------------

.. highlight:: xml

::

  <xsd:complexType name="CT_PPr">  <!-- denormalized -->
    <xsd:sequence>
      <!-- 34 others ... -->
      <xsd:element name="sectPr"    type="CT_SectPr"    minOccurs="0"/>
      <xsd:element name="pPrChange" type="CT_PPrChange" minOccurs="0"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="CT_SectPr">  <!-- denormalized -->
    <xsd:sequence>
      <xsd:choice minOccurs="0" maxOccurs="6"/>
        <xsd:element name="headerReference" type="CT_HdrFtrRef"/>
        <xsd:element name="footerReference" type="CT_HdrFtrRef"/>
      </xsd:choice>
      <xsd:element name="footnotePr"      type="CT_FtnProps"      minOccurs="0"/>
      <xsd:element name="endnotePr"       type="CT_EdnProps"      minOccurs="0"/>
      <xsd:element name="type"            type="CT_SectType"      minOccurs="0"/>
      <xsd:element name="pgSz"            type="CT_PageSz"        minOccurs="0"/>
      <xsd:element name="pgMar"           type="CT_PageMar"       minOccurs="0"/>
      <xsd:element name="paperSrc"        type="CT_PaperSource"   minOccurs="0"/>
      <xsd:element name="pgBorders"       type="CT_PageBorders"   minOccurs="0"/>
      <xsd:element name="lnNumType"       type="CT_LineNumber"    minOccurs="0"/>
      <xsd:element name="pgNumType"       type="CT_PageNumber"    minOccurs="0"/>
      <xsd:element name="cols"            type="CT_Columns"       minOccurs="0"/>
      <xsd:element name="formProt"        type="CT_OnOff"         minOccurs="0"/>
      <xsd:element name="vAlign"          type="CT_VerticalJc"    minOccurs="0"/>
      <xsd:element name="noEndnote"       type="CT_OnOff"         minOccurs="0"/>
      <xsd:element name="titlePg"         type="CT_OnOff"         minOccurs="0"/>
      <xsd:element name="textDirection"   type="CT_TextDirection" minOccurs="0"/>
      <xsd:element name="bidi"            type="CT_OnOff"         minOccurs="0"/>
      <xsd:element name="rtlGutter"       type="CT_OnOff"         minOccurs="0"/>
      <xsd:element name="docGrid"         type="CT_DocGrid"       minOccurs="0"/>
      <xsd:element name="printerSettings" type="CT_Rel"           minOccurs="0"/>
      <xsd:element name="sectPrChange"    type="CT_SectPrChange"  minOccurs="0"/>
    </xsd:sequence>
    <xsd:attribute name="rsidRPr"  type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidDel"  type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidR"    type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidSect" type="ST_LongHexNumber"/>
  </xsd:complexType>

  <xsd:complexType name="CT_HdrFtrRef">
    <xsd:attribute  ref="r:id"                  use="required"/>
    <xsd:attribute name="type" type="ST_HdrFtr" use="required"/>
  </xsd:complexType>

  <xsd:simpleType name="ST_HdrFtr">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="even"/>
      <xsd:enumeration value="default"/>
      <xsd:enumeration value="first"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="CT_SectType">
    <xsd:attribute name="val" type="ST_SectionMark"/>
  </xsd:complexType>

  <xsd:simpleType name="ST_SectionMark">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="nextPage"/>
      <xsd:enumeration value="nextColumn"/>
      <xsd:enumeration value="continuous"/>
      <xsd:enumeration value="evenPage"/>
      <xsd:enumeration value="oddPage"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="CT_PageSz">
    <xsd:attribute name="w"      type="s:ST_TwipsMeasure"/>
    <xsd:attribute name="h"      type="s:ST_TwipsMeasure"/>
    <xsd:attribute name="orient" type="ST_PageOrientation"/>
    <xsd:attribute name="code"   type="ST_DecimalNumber"/>
  </xsd:complexType>

  <xsd:simpleType name="ST_PageOrientation">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="portrait"/>
      <xsd:enumeration value="landscape"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="CT_PageMar">
    <xsd:attribute name="top"    type="ST_SignedTwipsMeasure" use="required"/>
    <xsd:attribute name="right"  type="s:ST_TwipsMeasure"     use="required"/>
    <xsd:attribute name="bottom" type="ST_SignedTwipsMeasure" use="required"/>
    <xsd:attribute name="left"   type="s:ST_TwipsMeasure"     use="required"/>
    <xsd:attribute name="header" type="s:ST_TwipsMeasure"     use="required"/>
    <xsd:attribute name="footer" type="s:ST_TwipsMeasure"     use="required"/>
    <xsd:attribute name="gutter" type="s:ST_TwipsMeasure"     use="required"/>
  </xsd:complexType>

  <xsd:simpleType name="ST_SignedTwipsMeasure">
    <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
  </xsd:simpleType>

  <xsd:complexType name="CT_Columns">
    <xsd:sequence minOccurs="0">
      <xsd:element name="col" type="CT_Column" maxOccurs="45"/>
    </xsd:sequence>
      <xsd:attribute name="equalWidth" type="s:ST_OnOff"/>
      <xsd:attribute name="space"      type="s:ST_TwipsMeasure"/>
      <xsd:attribute name="num"        type="ST_DecimalNumber"/>
      <xsd:attribute name="sep"        type="s:ST_OnOff"/>
  </xsd:complexType>

  <xsd:complexType name="CT_Column">
    <xsd:attribute name="w"     type="s:ST_TwipsMeasure"/>
    <xsd:attribute name="space" type="s:ST_TwipsMeasure"/>
  </xsd:complexType>