Table, Row, Cell — Aspose.Slides FOSS for Python API Reference

A Table is a graphical shape that organises content in rows and columns. Add a table to a slide with slide.shapes.add_table(), then navigate rows and cells to set text, format borders, and merge cells.

Package: aspose.slides_foss


Table

Access via slide.shapes.add_table(x, y, column_widths, row_heights) or by casting a shape from the shapes collection.

Properties

PropertyTypeAccessDescription
rowsRowCollectionReadOrdered collection of Row objects.
columnsColumnCollectionReadOrdered collection of Column objects.
table_formatTableFormatReadFill and border formatting for the whole table.
style_presetTableStylePresetRead/WriteBuilt-in table style GUID mapping (e.g. MEDIUM_STYLE_2_ACCENT_1).
first_rowboolRead/WriteApply special formatting to the first row.
first_colboolRead/WriteApply special formatting to the first column.
last_rowboolRead/WriteApply special formatting to the last row.
last_colboolRead/WriteApply special formatting to the last column.
horizontal_bandingboolRead/WriteDraw even rows with alternate formatting.
vertical_bandingboolRead/WriteDraw even columns with alternate formatting.
right_to_leftboolRead/WriteEnable right-to-left reading order.

Methods

MethodSignatureDescription
merge_cellsmerge_cells(cell1, cell2, allow_splitting) -> CellMerge all cells in the rectangular range defined by the two corner cells. Returns the anchor (top-left) cell.
set_text_formatset_text_format(source)Apply a PortionFormat or ParagraphFormat to all cells in the table at once.

Row

Represents a single row. Obtain via table.rows[i] or by iterating table.rows.

Properties

PropertyTypeAccessDescription
heightfloatReadCurrent row height in points.
minimal_heightfloatRead/WriteMinimum allowed row height in points.
row_formatRowFormatReadRow-level formatting object.

Row also implements CellCollection, so you can iterate it directly to get Cell objects.


RowCollection

Collection of Row objects belonging to a Table.

MemberDescription
__getitem__(i)Return the Row at zero-based index i.
__len__Number of rows.
__iter__Iterate over rows in order.

Cell

Represents a single table cell. Access via table.rows[r][c].

Properties

PropertyTypeAccessDescription
text_frameTextFrameReadText container for cell content.
cell_formatCellFormatReadBorder, fill, and margin formatting for this cell.
margin_leftfloatRead/WriteLeft inner margin in points (default ~7.2 pt).
margin_rightfloatRead/WriteRight inner margin in points.
margin_topfloatRead/WriteTop inner margin in points (default ~3.6 pt).
margin_bottomfloatRead/WriteBottom inner margin in points.
text_anchor_typeTextAnchorTypeRead/WriteVertical anchor: TOP, CENTER, BOTTOM, JUSTIFIED, DISTRIBUTED.
text_vertical_typeTextVerticalTypeRead/WriteText direction: HORIZONTAL, VERTICAL, VERTICAL270.
anchor_centerboolRead/WriteCentre text box horizontally inside the cell.
col_spanintReadNumber of columns spanned (1 = not merged).
row_spanintReadNumber of rows spanned (1 = not merged).
is_merged_cellboolReadTrue if this cell participates in a merge.
first_row_indexintReadZero-based row index of this cell.
first_column_indexintReadZero-based column index of this cell.
widthfloatReadCell width in points (sum of spanned column widths).
heightfloatReadCell height in points (sum of spanned row heights).
offset_xfloatReadDistance from the table left edge to this cell’s left edge, in points.
offset_yfloatReadDistance from the table top edge to this cell’s top edge, in points.
tableTableReadThe parent Table.
first_rowRowReadThe Row that contains this cell.
first_columnColumnReadThe Column that contains this cell.

CellCollection

Collection of Cell objects belonging to a Row.

MemberDescription
__getitem__(i)Return the Cell at zero-based column index i.
__len__Number of cells.
__iter__Iterate over cells left to right.

Column

Represents a single column. Obtain via table.columns[i].

Properties

PropertyTypeAccessDescription
widthfloatRead/WriteColumn width in points.
column_formatColumnFormatReadColumn-level formatting object.

ColumnCollection

Collection of Column objects belonging to a Table.

MemberDescription
__getitem__(i)Return the Column at zero-based index i.
__len__Number of columns.
__iter__Iterate over columns left to right.

Usage Example

Create a 3x3 table and populate cells

import aspose.slides_foss as slides
from aspose.slides_foss import FillType, TextAlignment
from aspose.slides_foss.drawing import Color
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    slide = prs.slides[0]

    # Column widths and row heights in points
    col_widths = [120.0, 120.0, 120.0]
    row_heights = [40.0, 40.0, 40.0]

    table = slide.shapes.add_table(50, 80, col_widths, row_heights)

    # Set header row text
    headers = ["Name", "Role", "Department"]
    for ci, header in enumerate(headers):
        cell = table.rows[0][ci]
        cell.text_frame.text = header
        fmt = cell.text_frame.paragraphs[0].portions[0].portion_format
        from aspose.slides_foss import NullableBool
        fmt.font_bold = NullableBool.TRUE

    # Populate data row
    data = ["Alice", "Engineer", "R&D"]
    for ci, value in enumerate(data):
        table.rows[1][ci].text_frame.text = value

    # Merge two cells in the last row
    table.merge_cells(table.rows[2][1], table.rows[2][2], False)
    table.rows[2][1].text_frame.text = "Merged cell"

    prs.save("table-demo.pptx", SaveFormat.PPTX)

See Also