Shape collections
SlideShapes
Sequence of shapes appearing on a slide. The first shape in the sequence is the backmost in z-order and the last shape is topmost. Supports indexed access,len(), index(), and iteration.
Accessed via the shapes property of a Slide object.
Methods
add_chart()
Add a new chart to the slide.Chart type from the XlChartType enumeration
Horizontal position of chart in EMU
Vertical position of chart in EMU
Width of chart in EMU
Height of chart in EMU
ChartData object containing the data for the chart
GraphicFrame shape containing the chart. Access the chart via the
.chart property.add_connector()
Add a newly created connector shape to the slide.Type of connector from MsoConnectorType enumeration
Horizontal position of begin point in EMU
Vertical position of begin point in EMU
Horizontal position of end point in EMU
Vertical position of end point in EMU
The newly created connector shape
add_group_shape()
Return a newly appended group shape.Optional sequence of shapes to include in the group
The newly created group shape
add_picture()
Add a picture shape displaying the specified image.Path to image file (string) or file-like object containing image bytes
Horizontal position of left edge in EMU
Vertical position of top edge in EMU
Width of picture in EMU. If None, native image width is used.
Height of picture in EMU. If None, native image height is used.
The newly created picture shape
None, the native size of the image is used. If only one is specified, the other is calculated to preserve aspect ratio. If both are specified, the picture is stretched to fit.
add_shape()
Return a new autoshape appended to the slide.Member of MsoAutoShapeType enumeration specifying the shape type
Horizontal position in EMU
Vertical position in EMU
Width in EMU
Height in EMU
The newly created shape
add_table()
Add a table to the slide.Number of rows in the table
Number of columns in the table
Horizontal position in EMU
Vertical position in EMU
Total width of table in EMU
Total height of table in EMU
GraphicFrame shape containing the table. Access the table via the
.table property.add_textbox()
Return a newly added text box shape.Horizontal position in EMU
Vertical position in EMU
Width in EMU
Height in EMU
The newly created text box shape
build_freeform()
Return a FreeformBuilder object to specify a freeform shape.Starting X position in local coordinates
Starting Y position in local coordinates
Scale factor(s) for local coordinates. Can be a single float or tuple of (x_scale, y_scale)
Builder object for creating freeform shapes
index()
Return the index of the specified shape in this sequence.The shape to locate
Zero-based index of the shape
ValueError if the shape is not in the collection.
Properties
placeholders
SlidePlaceholders - Sequence of placeholder shapes in this slide.
title
Shape | None - The title placeholder shape on the slide. None if the slide has no title placeholder.
turbo_add_enabled
bool - True if turbo-add mode is enabled. Read/write.
EXPERIMENTAL: This feature can radically improve performance when adding large numbers (hundreds) of shapes to a slide by caching the last shape ID used. Only use a single Slide object when this is enabled to avoid ID collisions.
Shape objects
BaseShape
Base class for all shape objects. Properties and methods common to all shapes.Properties
click_action
ActionSetting - Instance providing access to click behaviors like hyperlinks.
element
ShapeElement - The lxml element for this shape (e.g. CT_Shape instance).
has_chart
bool - True if this shape is a graphic frame containing a chart.
has_table
bool - True if this shape is a graphic frame containing a table.
has_text_frame
bool - True if this shape can contain text.
height
Length - Distance between top and bottom extents of shape in EMU. Read/write.
is_placeholder
bool - True if this shape is a placeholder.
left
Length - Distance of left edge of this shape from left edge of slide in EMU. Read/write.
name
str - Name of this shape, e.g. ‘Picture 7’. Read/write.
placeholder_format
_PlaceholderFormat - Provides access to placeholder-specific properties.
Raises ValueError if the shape is not a placeholder.
rotation
float - Degrees of clockwise rotation. Read/write.
Negative values can be assigned to indicate counter-clockwise rotation (e.g. -45.0 becomes 315.0).
shadow
ShadowFormat - Object providing access to shadow properties for this shape.
shape_id
int - Positive integer uniquely identifying this shape among all shapes on the slide. Read-only.
shape_type
MSO_SHAPE_TYPE - Member of MSO_SHAPE_TYPE classifying this shape by type.
top
Length - Distance from top edge of slide to top edge of this shape in EMU. Read/write.
width
Length - Distance between left and right extents of this shape in EMU. Read/write.
Shape (AutoShape)
Autoshape objects, including text boxes and placeholders. Corresponds to thep:sp element.
Properties
adjustments
AdjustmentCollection - Collection of adjustment values for this shape. Read-only.
Adjustment values correspond to the position of adjustment handles (yellow diamonds) that appear on certain autoshapes.
auto_shape_type
MSO_SHAPE - Enumeration value identifying the type of this autoshape.
Like MSO_SHAPE.ROUNDED_RECTANGLE. Raises ValueError if this shape is not an autoshape.
fill
FillFormat - Instance for this shape providing access to fill properties.
line
LineFormat - Instance providing access to line properties like color and width.
text
str - Text in shape as a single string. Read/write.
The returned string contains newline characters (\n) separating paragraphs and vertical-tab characters (\v) for line breaks.
text_frame
TextFrame - Instance for this shape containing the text and providing access to text formatting.
Picture
Picture shape that places an image on a slide. Based on thep:pic element.
Properties
auto_shape_type
MSO_SHAPE | None - Member of MSO_SHAPE indicating the masking shape. Read/write.
A picture can be masked by autoshapes like ellipse or triangle. Default is MSO_SHAPE.RECTANGLE (no cropping). Returns None for custom geometry.
crop_bottom
float - Relative portion cropped from shape bottom. Read/write.
1.0 represents 100%. For example, 0.25 represents 25%. Negative values and values greater than 1.0 are valid.
crop_left
float - Relative portion cropped from left of shape. Read/write.
crop_right
float - Relative portion cropped from right of shape. Read/write.
crop_top
float - Relative portion cropped from shape top. Read/write.
image
Image - The Image object for this picture providing access to image properties and bytes.
line
LineFormat - Provides access to properties of the picture outline.
shape_type
MSO_SHAPE_TYPE - Unconditionally MSO_SHAPE_TYPE.PICTURE.
GraphicFrame
Container shape for table, chart, smart art, and media objects. Corresponds top:graphicFrame element.
Properties
chart
Chart - The Chart object contained in this graphic frame.
Raises ValueError if this graphic frame does not contain a chart.
has_chart
bool - True if this graphic frame contains a chart.
has_table
bool - True if this graphic frame contains a table.
ole_format
_OleFormat - Provides attributes on embedded OLE object.
Raises ValueError if this is not an OLE-object shape.
shape_type
MSO_SHAPE_TYPE - Member identifying the type of this shape.
Possible values: MSO_SHAPE_TYPE.CHART, MSO_SHAPE_TYPE.TABLE, MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT, MSO_SHAPE_TYPE.LINKED_OLE_OBJECT, or None (e.g. for SmartArt).
table
Table - The Table object contained in this graphic frame.
Raises ValueError if this graphic frame does not contain a table.
Connector
Connector (line) shape. A connector is a linear shape having endpoints that can be connected to other objects.Properties
begin_x
Length - X-position of the begin point of this connector in EMU. Read/write.
begin_y
Length - Y-position of the begin point of this connector in EMU. Read/write.
end_x
Length - X-position of the end point of this connector in EMU. Read/write.
end_y
Length - Y-position of the end point of this connector in EMU. Read/write.
line
LineFormat - Instance providing access to line properties.
shape_type
MSO_SHAPE_TYPE - Unconditionally MSO_SHAPE_TYPE.LINE.
Methods
begin_connect()
EXPERIMENTAL - Connect the beginning of this connector to a shape.Shape to connect to
Index of connection point on the shape (0-based)
end_connect()
EXPERIMENTAL - Connect the ending of this connector to a shape.Shape to connect to
Index of connection point on the shape (0-based)
GroupShape
A shape that acts as a container for other shapes.Properties
has_text_frame
bool - Unconditionally False. A group shape cannot contain text.
shape_type
MSO_SHAPE_TYPE - Unconditionally MSO_SHAPE_TYPE.GROUP.
shapes
GroupShapes - Collection of shapes contained by this group.
Provides access to member shapes and methods for adding new ones.
Notes
- A group shape cannot have a click action or text frame
- Attempting to access
click_actionraisesTypeError - The
shadowproperty raisesNotImplementedError(not yet supported)
Movie
A movie shape that places a video on a slide. Like Picture, a movie is based on thep:pic element.
Properties
media_format
_MediaFormat - Provides access to formatting properties for the movie.
media_type
PP_MEDIA_TYPE - Unconditionally PP_MEDIA_TYPE.MOVIE.
poster_frame
Image | None - Image object containing poster frame for this movie.
Returns None if this movie has no poster frame (uncommon).
shape_type
MSO_SHAPE_TYPE - Unconditionally MSO_SHAPE_TYPE.MEDIA.