forked from python-openxml/python-docx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyles.py
More file actions
40 lines (33 loc) · 1004 Bytes
/
styles.py
File metadata and controls
40 lines (33 loc) · 1004 Bytes
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
# encoding: utf-8
"""
Custom element classes related to the styles part
"""
from docx.oxml.shared import nsmap, OxmlBaseElement, qn
class CT_Style(OxmlBaseElement):
"""
A ``<w:style>`` element, representing a style definition
"""
@property
def pPr(self):
return self.find(qn('w:pPr'))
class CT_Styles(OxmlBaseElement):
"""
``<w:styles>`` element, the root element of a styles part, i.e.
styles.xml
"""
def style_having_styleId(self, styleId):
"""
Return the ``<w:style>`` child element having ``styleId`` attribute
matching *styleId*.
"""
xpath = './w:style[@w:styleId="%s"]' % styleId
try:
return self.xpath(xpath, namespaces=nsmap)[0]
except IndexError:
raise KeyError('no <w:style> element with styleId %d' % styleId)
@property
def style_lst(self):
"""
List of <w:style> child elements.
"""
return self.findall(qn('w:style'))