styles
styles
¶
Custom element classes related to the styles part.
CT_PPrDefault
¶
Bases: BaseOxmlElement
w:pPrDefault element, wrapping the document-wide default paragraph formatting.
CT_RPrDefault
¶
CT_DocDefaults
¶
Bases: BaseOxmlElement
w:docDefaults element, the bottom of the formatting inheritance chain.
Whatever is set here applies to the whole document before any style or direct formatting. For many real documents it is the only place the base font and the base paragraph spacing are set.
CT_LatentStyles
¶
Bases: BaseOxmlElement
w:latentStyles element, defining behavior defaults for latent styles and
containing w:lsdException child elements that each override those defaults for a
named latent style.
CT_LsdException
¶
Bases: BaseOxmlElement
<w:lsdException> element, defining override visibility behaviors for a named
latent style.
CT_Style
¶
Bases: BaseOxmlElement
A <w:style> element, representing a style definition.
base_style
property
¶
Sibling CT_Style element this style is based on or None if no base style or
base style not found.
link_val
property
writable
¶
Value of w:link/@w:val or None if not present.
The id of the paired style of the other kind: a paragraph style's w:link names
the character style holding its run formatting, and vice versa. Copying one
without the other leaves a dangling pair.
numId_val
property
writable
¶
Value of ./w:pPr/w:numPr/w:numId/@w:val, or None if not present.
A numbering reference points into the numbering part, so it means nothing on its own in another document.
next_style
property
¶
Sibling CT_Style element identified by the value of w:name/@w:val or None
if no value is present or no style with that style id is found.
semiHidden_val
property
writable
¶
Value of <w:semiHidden> child or False if not present.
uiPriority_val
property
writable
¶
Value of <w:uiPriority> child or None if not present.
unhideWhenUsed_val
property
writable
¶
Value of w:unhideWhenUsed/@w:val or False if not present.
CT_Styles
¶
Bases: BaseOxmlElement
<w:styles> element, the root element of a styles part, i.e. styles.xml.
add_style_of_type
¶
Return a newly added w:style element having name and style_type.
w:style/@customStyle is set based on the value of builtin.
Source code in src/docx/oxml/styles.py
default_for
¶
Return w:style[@w:type="*{style_type}*][-1] or None if not found.
Source code in src/docx/oxml/styles.py
get_by_id
¶
get_by_id(styleId: str) -> CT_Style | None
w:style child where @styleId = styleId.
None if not found.
get_by_name
¶
get_by_name(name: str) -> CT_Style | None
w:style child with w:name grandchild having value name.
Matched exactly first, then case-insensitively. Word treats style names as case-insensitive, and a built-in style has two spellings — the UI name ("Heading 1") and the internal name Word stores ("heading 1"). Documents written by other generators routinely store the UI casing, and without the second pass the style is present but unreachable.
The exact pass runs first so that a document containing both spellings resolves to the one asked for rather than to whichever comes first.
None if not found.
Source code in src/docx/oxml/styles.py
styleId_from_name
¶
Return the style id corresponding to name, taking into account special-case
names such as 'Heading 1'.