forked from python-openxml/python-docx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsection.py
More file actions
185 lines (153 loc) · 5.3 KB
/
section.py
File metadata and controls
185 lines (153 loc) · 5.3 KB
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
# encoding: utf-8
"""
The |Section| object and related proxy classes.
"""
from __future__ import absolute_import, print_function, unicode_literals
from collections import Sequence
class Sections(Sequence):
"""
Sequence of |Section| objects corresponding to the sections in the
document. Supports ``len()``, iteration, and indexed access.
"""
def __init__(self, document_elm):
super(Sections, self).__init__()
self._document_elm = document_elm
def __getitem__(self, key):
if isinstance(key, slice):
sectPr_lst = self._document_elm.sectPr_lst[key]
return [Section(sectPr) for sectPr in sectPr_lst]
sectPr = self._document_elm.sectPr_lst[key]
return Section(sectPr)
def __iter__(self):
for sectPr in self._document_elm.sectPr_lst:
yield Section(sectPr)
def __len__(self):
return len(self._document_elm.sectPr_lst)
class Section(object):
"""
Document section, providing access to section and page setup settings.
"""
def __init__(self, sectPr):
super(Section, self).__init__()
self._sectPr = sectPr
@property
def bottom_margin(self):
"""
|Length| object representing the bottom margin for all pages in this
section in English Metric Units.
"""
return self._sectPr.bottom_margin
@bottom_margin.setter
def bottom_margin(self, value):
self._sectPr.bottom_margin = value
@property
def footer_distance(self):
"""
|Length| object representing the distance from the bottom edge of the
page to the bottom edge of the footer. |None| if no setting is present
in the XML.
"""
return self._sectPr.footer
@footer_distance.setter
def footer_distance(self, value):
self._sectPr.footer = value
@property
def gutter(self):
"""
|Length| object representing the page gutter size in English Metric
Units for all pages in this section. The page gutter is extra spacing
added to the *inner* margin to ensure even margins after page
binding.
"""
return self._sectPr.gutter
@gutter.setter
def gutter(self, value):
self._sectPr.gutter = value
@property
def header_distance(self):
"""
|Length| object representing the distance from the top edge of the
page to the top edge of the header. |None| if no setting is present
in the XML.
"""
return self._sectPr.header
@header_distance.setter
def header_distance(self, value):
self._sectPr.header = value
@property
def left_margin(self):
"""
|Length| object representing the left margin for all pages in this
section in English Metric Units.
"""
return self._sectPr.left_margin
@left_margin.setter
def left_margin(self, value):
self._sectPr.left_margin = value
@property
def orientation(self):
"""
Member of the :ref:`WdOrientation` enumeration specifying the page
orientation for this section, one of ``WD_ORIENT.PORTRAIT`` or
``WD_ORIENT.LANDSCAPE``.
"""
return self._sectPr.orientation
@orientation.setter
def orientation(self, value):
self._sectPr.orientation = value
@property
def page_height(self):
"""
Total page height used for this section, inclusive of all edge spacing
values such as margins. Page orientation is taken into account, so
for example, its expected value would be ``Inches(8.5)`` for
letter-sized paper when orientation is landscape.
"""
return self._sectPr.page_height
@page_height.setter
def page_height(self, value):
self._sectPr.page_height = value
@property
def page_width(self):
"""
Total page width used for this section, inclusive of all edge spacing
values such as margins. Page orientation is taken into account, so
for example, its expected value would be ``Inches(11)`` for
letter-sized paper when orientation is landscape.
"""
return self._sectPr.page_width
@page_width.setter
def page_width(self, value):
self._sectPr.page_width = value
@property
def right_margin(self):
"""
|Length| object representing the right margin for all pages in this
section in English Metric Units.
"""
return self._sectPr.right_margin
@right_margin.setter
def right_margin(self, value):
self._sectPr.right_margin = value
@property
def start_type(self):
"""
The member of the :ref:`WdSectionStart` enumeration corresponding to
the initial break behavior of this section, e.g.
``WD_SECTION.ODD_PAGE`` if the section should begin on the next odd
page.
"""
return self._sectPr.start_type
@start_type.setter
def start_type(self, value):
self._sectPr.start_type = value
@property
def top_margin(self):
"""
|Length| object representing the top margin for all pages in this
section in English Metric Units.
"""
return self._sectPr.top_margin
@top_margin.setter
def top_margin(self, value):
self._sectPr.top_margin = value