SlidePart
paper-pptx 0.2.0 API reference
Slide part. Corresponds to package files ppt/slides/slide[1-9][0-9]*.xml.
Attributes
blob
attributeblobbytesbytes XML serialization of this part.
content_type
attributecontent_typestrContent-type (MIME-type) of this part.
has_notes_slide
attributehas_notes_slideReturn True if this slide has a notes slide, False otherwise. A notes
slide is created by the :attr:notes_slide property when one doesn't
exist; use this property to test for a notes slide without the
possible side-effect of creating one.
name
attributenamestrInternal name of this slide.
notes_slide
attributenotes_slideNotesSlideThe NotesSlide instance associated with this slide.
If the slide does not have a notes slide, a new one is created. The same single instance is returned on each call.
package
attributepackagePackagePackage this part belongs to.
part
attributepartThis part.
This is part 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
attributepartnamePackURIPackURI partname for this part, e.g. "/ppt/slides/slide1.xml".
rels
attributerels_RelationshipsCollection of relationships from this part to other parts.
slide
attributeslideThe Slide object representing this slide part.
slide_id
attributeslide_idintReturn the slide identifier stored in the presentation part for this slide part.
slide_layout
attributeslide_layoutSlideLayoutSlideLayout object the slide in this part inherits appearance from.
Functions
add_chart_part
funcadd_chart_part(chart_type: XL_CHART_TYPE, chart_data: ChartData)Return str rId of new ChartPart object containing chart of chart_type.
The chart depicts chart_data and is related to the slide contained in this
part by rId.
paramchart_typeXL_CHART_TYPEparamchart_dataChartDataadd_embedded_ole_object_part
funcadd_embedded_ole_object_part(prog_id: PROG_ID | str, ole_object_file: str | IO[bytes])Return rId of newly-added OLE-object part formed from ole_object_file.
paramprog_idPROG_ID | strparamole_object_filestr | IO[bytes]drop_rel
funcdrop_rel(rId: str) -> NoneRemove relationship identified by rId if its reference count is under 2.
Relationships with a reference count of 0 are implicit relationships. Note that only XML parts can drop relationships.
paramrIdstrReturns
Noneget_image
funcget_image(rId: str) -> ImageReturn an Image object containing the image related to this slide by rId.
Raises KeyError if no image is related by that id, which would generally indicate a
corrupted .pptx file.
paramrIdstrReturns
pptx.parts.image.Imageget_or_add_image_part
funcget_or_add_image_part(image_file: str | IO[bytes])Return (image_part, rId) pair corresponding to image_file.
The returned ImagePart object contains the image in image_file and is
related to this slide with the key rId. If either the image part or
relationship already exists, they are reused, otherwise they are newly created.
paramimage_filestr | IO[bytes]get_or_add_video_media_part
funcget_or_add_video_media_part(video: Video) -> tuple[str, str]Return rIds for media and video relationships to media part.
A new MediaPart object is created if it does not already exist
(such as would occur if the same video appeared more than once in
a presentation). Two relationships to the media part are created,
one each with MEDIA and VIDEO relationship types. The need for two
appears to be for legacy support for an earlier (pre-Office 2010)
PowerPoint media embedding strategy.
paramvideoVideoReturns
tuple[str, str]load
funcload(partname: PackURI, content_type: str, package: Package, blob: bytes)Return instance of cls loaded with parsed XML from blob.
parampartnamePackURIparamcontent_typestrparampackagePackageparamblobbytesload_rels_from_xml
funcload_rels_from_xml(xml_rels: CT_Relationships, parts: dict[PackURI, Part]) -> Noneload _Relationships for this part from xml_rels.
Part references are resolved using the parts dict that maps each partname to the loaded
part with that partname. These relationships are loaded from a serialized package and so
already have assigned rIds. This method is only used during package loading.
paramxml_relsCT_Relationshipsparampartsdict[PackURI, Part]Returns
Nonenew
funcnew(partname, package, slide_layout_part)Return newly-created blank slide part.
The new slide-part has partname and a relationship to slide_layout_part.
parampartnameparampackageparamslide_layout_partpart_related_by
funcpart_related_by(reltype: str) -> PartReturn (single) part having relationship to this package of reltype.
Raises KeyError if no such relationship is found and ValueError if more than one such
relationship is found.
paramreltypestrReturns
pptx.opc.package.Partrelate_to
funcrelate_to(target: Part | str, reltype: str, is_external: bool = False) -> strReturn rId key of relationship of reltype to target.
If such a relationship already exists, its rId is returned. Otherwise the relationship is added and its new rId returned.
paramtargetPart | strparamreltypestrparamis_externalbool= FalseReturns
strrelated_part
funcrelated_part(rId: str) -> PartReturn related Part subtype identified by rId.
paramrIdstrReturns
pptx.opc.package.Parttarget_ref
functarget_ref(rId: str) -> strReturn URL contained in target ref of relationship identified by rId.
paramrIdstrReturns
str