object
object
¶
The EmbeddedObject proxy — a file embedded in a document as an OLE object.
Word can embed a whole file inside a document and show it as an icon or a preview image that opens the original application on double-click. The read side matters on its own: for a document containing embedded attachments there was previously no way to discover that they exist, let alone extract them.
This is a different thing from the two neighbouring features. Document.add_alt_chunk()
imports content and dissolves it into the document when Word opens the file; an OLE
object stays a distinct embedded file. Run.add_picture() embeds an image with no
underlying document.
EmbeddedObject
¶
EmbeddedObject(
object_elm: CT_Object, parent: ProvidesStoryPart
)
Bases: StoryChild
An OLE object embedded in a run — a spreadsheet, a PDF, another document.
Reached through Run.embedded_objects or Document.embedded_objects.
Source code in src/docx/object.py
prog_id
property
¶
The application Word launches for this object, e.g. "Excel.Sheet.12".
None when the object names none. This is what tells Word which application to
open; an object whose ProgID names nothing installed is one Word shows but
cannot open.
is_linked
property
¶
True when the object links to an external file rather than embedding it.
A linked object's bytes are not in the package, so blob is None.
shows_icon
property
¶
True when Word shows this object as an icon rather than a preview.
embedded_part
property
¶
embedded_part: Part | None
The package part holding the embedded file, or None.
None for a linked object, and for an embedded one whose relationship the
document does not resolve — which is a broken document rather than an error
here.
blob
property
¶
content_type
property
¶
The content type of the embedded part, or None when there is no part.
filename
property
¶
The partname's basename, e.g. "oleObject1.bin", or None.
OOXML does not record the original file name of an embedded object; this is the name of the part it landed in, which is what a caller extracting it has to work with.
add_embedded_object
¶
add_embedded_object(
run: object,
path_or_stream: str | PathLike[str] | IO[bytes],
*,
icon: str | PathLike[str] | IO[bytes],
prog_id: str | None = None,
width: Length | None = None,
height: Length | None = None,
) -> EmbeddedObject
Embed path_or_stream in run as an OLE object; see Run.add_embedded_object.
Source code in src/docx/object.py
iter_embedded_objects
¶
iter_embedded_objects(
element: object, parent: ProvidesStoryPart
) -> list[EmbeddedObject]
The EmbeddedObject instances under element, in document order.