Skip to main content

GraphicFrame

Container shape for table, chart, smart art, and media objects. Corresponds to a p:graphicFrame element in the shape tree.

Properties

chart
Chart
The |Chart| object containing the chart in this graphic frame.Raises ValueError if this graphic frame does not contain a chart.
chart_part
ChartPart
The |ChartPart| object containing the chart 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 object, False otherwise.When True, the chart object can be accessed using the .chart property.
has_table
bool
True if this graphic frame contains a table object, False otherwise.When True, the table object can be accessed using the .table property.
ole_format
_OleFormat
_OleFormat object for this graphic-frame shape.Raises ValueError on a GraphicFrame instance that does not contain an OLE object.A shape that contains an OLE object will have .shape_type of either EMBEDDED_OLE_OBJECT or LINKED_OLE_OBJECT.
shadow
ShadowFormat
Unconditionally raises NotImplementedError.Access to the shadow effect for graphic-frame objects is content-specific (i.e. different for charts, tables, etc.) and has not yet been implemented.
shape_type
MSO_SHAPE_TYPE | None
Optional member of MSO_SHAPE_TYPE identifying the type of this shape.Possible values are:
  • MSO_SHAPE_TYPE.CHART
  • MSO_SHAPE_TYPE.TABLE
  • MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT
  • MSO_SHAPE_TYPE.LINKED_OLE_OBJECT
This value is None when none of these four types apply, for example when the shape contains SmartArt.
table
Table
The |Table| object contained in this graphic frame.Raises ValueError if this graphic frame does not contain a table.

Example: Working with Tables

from pptx import Presentation
from pptx.util import Inches

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])

# Add a table
rows, cols = 3, 3
left = Inches(2.0)
top = Inches(2.0)
width = Inches(6.0)
height = Inches(2.0)

graphic_frame = slide.shapes.add_table(rows, cols, left, top, width, height)

# Check if it has a table
if graphic_frame.has_table:
    table = graphic_frame.table
    
    # Access table cells
    table.cell(0, 0).text = 'Header 1'
    table.cell(0, 1).text = 'Header 2'
    table.cell(1, 0).text = 'Row 1, Col 1'

Example: Working with Charts

from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])

# Create chart data
chart_data = CategoryChartData()
chart_data.categories = ['Q1', 'Q2', 'Q3', 'Q4']
chart_data.add_series('Sales', (10, 15, 20, 25))

# Add chart
x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
graphic_frame = slide.shapes.add_chart(
    XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
)

# Access the chart
if graphic_frame.has_chart:
    chart = graphic_frame.chart
    chart.has_legend = True

_OleFormat

Provides attributes on an embedded OLE object.

Properties

blob
bytes | None
Optional bytes of OLE object, suitable for loading or saving as a file.This value is None if the embedded object does not represent a “file”.
prog_id
str | None
str “progId” attribute of this embedded OLE object.The progId is a str like “Excel.Sheet.12” that identifies the “file-type” of the embedded object, or perhaps more precisely, the application (aka. “server” in OLE parlance) to be used to open this object.
show_as_icon
bool | None
True when OLE object should appear as an icon (rather than preview).

Example: Working with OLE Objects

# Access OLE object from a graphic frame
if graphic_frame.shape_type == MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT:
    ole_format = graphic_frame.ole_format
    
    # Get the program ID
    print(f"Program ID: {ole_format.prog_id}")
    
    # Extract the blob data
    if ole_format.blob:
        with open('extracted_file.xlsx', 'wb') as f:
            f.write(ole_format.blob)

Build docs developers (and LLMs) love