Paper Office
paper-docxAPI referencestyles.styles

Styles

paper-docx 0.2.0 API reference

Provides access to the styles defined in a document.

Accessed using the :attr:.Document.styles property. Supports len(), iteration, and dictionary-style access by style name.

Styles(styles: CT_Styles)

Attributes

element

attributeelement

The lxml element proxied by this object.

latent_styles

attributelatent_styles

A LatentStyles object providing access to the default behaviors for latent styles and the collection of _LatentStyle objects that define overrides of those defaults for a particular named latent style.

part

attributepartXmlPart

The package part containing this object.

Functions

__contains__

func__contains__(name)

Enables in operator on style name.

paramname

__getitem__

func__getitem__(key: str)

Enables dictionary-style access by UI name.

Lookup by style id is deprecated, triggers a warning, and will be removed in a near-future release.

paramkeystr

__iter__

func__iter__()

__len__

func__len__()

add_style

funcadd_style(name, style_type, builtin=False)

Return a newly added style object of style_type and identified by name.

A builtin style can be defined by passing True for the optional builtin argument.

paramname
paramstyle_type
parambuiltin
= False

default

funcdefault(style_type: WD_STYLE_TYPE)

Return the default style for style_type or None if no default is defined for that type (not common).

paramstyle_typeWD_STYLE_TYPE

get_by_id

funcget_by_id(style_id: str | None, style_type: WD_STYLE_TYPE)

Return the style of style_type matching style_id.

Returns the default for style_type if style_id is not found or is None, or if the style having style_id is not of style_type.

paramstyle_idstr | None
paramstyle_typeWD_STYLE_TYPE

get_style_id

funcget_style_id(style_or_name, style_type)

Return the id of the style corresponding to style_or_name, or None if style_or_name is None.

If style_or_name is not a style object, the style is looked up using style_or_name as a style name, raising ValueError if no style with that name is defined. Raises ValueError if the target style is not of style_type.

paramstyle_or_name
paramstyle_type

On this page