StylesPart
paper-docx 0.2.0 API reference
Proxy for the styles.xml part containing style definitions for a document or glossary.
Attributes
blob
attributeblobcontent_type
attributecontent_typeContent type of this part.
element
attributeelementThe root XML element of this XML part.
package
attributepackageOpcPackage instance this part belongs to.
part
attributepartPart of the parent protocol, "children" of the document will not know the part that contains them so must ask their parent object.
That chain of delegation ends here for child objects.
partname
attributepartnamePackURI instance holding partname of this part, e.g.
'/ppt/slides/slide1.xml'.
related_parts
attributerelated_partsDictionary mapping related parts by rId, so child objects can resolve
explicit relationships present in the part XML, e.g. sldIdLst to a specific
Slide instance.
rels
attributerelsRelationships instance holding the relationships for this part.
styles
attributestylesThe _Styles instance containing the styles (<w:style> element proxies) for
this styles part.
Functions
after_unmarshal
funcafter_unmarshal()Entry point for post-unmarshaling processing, for example to parse the part XML.
May be overridden by subclasses without forwarding call to super.
before_marshal
funcbefore_marshal()Entry point for pre-serialization processing, for example to finalize part naming if necessary.
May be overridden by subclasses without forwarding call to super.
default
funcdefault(package: OpcPackage) -> StylesPartReturn a newly created styles part, containing a default set of elements.
parampackageOpcPackageReturns
docx.parts.styles.StylesPartdrop_rel
funcdrop_rel(rId: str)Remove the relationship identified by rId if its reference count is less
than 2.
Relationships with a reference count of 0 are implicit relationships.
paramrIdstrload
funcload(partname: PackURI, content_type: str, blob: bytes, package: Package)parampartnamePackURIparamcontent_typestrparamblobbytesparampackagePackageload_rel
funcload_rel(reltype: str, target: Part | str, rId: str, is_external: bool = False)Return newly added _Relationship instance of reltype.
The new relationship relates the target part to this part with key rId.
Target mode is set to RTM.EXTERNAL if is_external is True. Intended for
use during load from a serialized package, where the rId is well-known. Other
methods exist for adding a new relationship to a part when manipulating a part.
paramreltypestrparamtargetPart | strparamrIdstrparamis_externalbool= Falsepart_related_by
funcpart_related_by(reltype: str) -> PartReturn part to which this part has a relationship of reltype.
Raises KeyError if no such relationship is found and ValueError if more than
one such relationship is found. Provides ability to resolve implicitly related
part, such as Slide -> SlideLayout.
paramreltypestrReturns
docx.opc.part.Partrelate_to
funcrelate_to(target: Part | str, reltype: str, is_external: bool = False) -> strReturn rId key of relationship of reltype to target.
The returned rId is from an existing relationship if there is one, otherwise a
new relationship is created.
paramtargetPart | strparamreltypestrparamis_externalbool= FalseReturns
strtarget_ref
functarget_ref(rId: str) -> strReturn URL contained in target ref of relationship identified by rId.
paramrIdstrReturns
str