Adding a table
Tables are added to slides using theadd_table() method:
add_table() returns a GraphicFrame shape that contains the table, not the table itself. Access the table via the table property.Understanding table structure
A PowerPoint table consists of:- Cells: Individual content containers within the table
- Rows: Horizontal sequences of cells
- Columns: Vertical sequences of cells
- Grid: The underlying cell structure (may be obscured by merged cells)
Accessing cells
Access individual cells using zero-based row and column indices:Iterating through cells
Iterate through all cells in the table:Working with rows and columns
Access rows and columns using list notation:Formatting cells
Cells contain a text frame and can be formatted like auto shapes:- Text formatting
- Cell fill
- Cell margins
Merging cells
Merge cells by specifying two diagonal corners:The merge origin is always the top-left cell of the merged region. Content from all merged cells is migrated to the merge origin as separate paragraphs.
Splitting merged cells
Split a merged cell back to individual grid cells:Table styling
Apply table-level formatting options:These properties apply formatting defined in the table style. The actual visual effect depends on the table style in use.
Complete examples
Advanced techniques
Finding merged cells
Checking for merged cells
Accessing only visible cells
Inserting tables into placeholders
Use table placeholders from slide layouts:Best practices
- Enable
first_rowfor tables with headers - Use
horz_bandingfor better readability of data rows - Merge cells only when necessary (complex merging can be confusing)
- Always check
is_spannedwhen iterating cells to avoid hidden cells - Use consistent cell margins for professional appearance
- Center-align headers for better visual balance
- Set explicit column widths for data-heavy tables