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
| Property | Type | Access | Description |
|---|---|---|---|
rows | RowCollection | Read | Ordered collection of Row objects. |
columns | ColumnCollection | Read | Ordered collection of Column objects. |
table_format | TableFormat | Read | Fill and border formatting for the whole table. |
style_preset | TableStylePreset | Read/Write | Built-in table style GUID mapping (e.g. MEDIUM_STYLE_2_ACCENT_1). |
first_row | bool | Read/Write | Apply special formatting to the first row. |
first_col | bool | Read/Write | Apply special formatting to the first column. |
last_row | bool | Read/Write | Apply special formatting to the last row. |
last_col | bool | Read/Write | Apply special formatting to the last column. |
horizontal_banding | bool | Read/Write | Draw even rows with alternate formatting. |
vertical_banding | bool | Read/Write | Draw even columns with alternate formatting. |
right_to_left | bool | Read/Write | Enable right-to-left reading order. |
Methods
| Method | Signature | Description |
|---|---|---|
merge_cells | merge_cells(cell1, cell2, allow_splitting) -> Cell | Merge all cells in the rectangular range defined by the two corner cells. Returns the anchor (top-left) cell. |
set_text_format | set_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
| Property | Type | Access | Description |
|---|---|---|---|
height | float | Read | Current row height in points. |
minimal_height | float | Read/Write | Minimum allowed row height in points. |
row_format | RowFormat | Read | Row-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.
| Member | Description |
|---|---|
__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
| Property | Type | Access | Description |
|---|---|---|---|
text_frame | TextFrame | Read | Text container for cell content. |
cell_format | CellFormat | Read | Border, fill, and margin formatting for this cell. |
margin_left | float | Read/Write | Left inner margin in points (default ~7.2 pt). |
margin_right | float | Read/Write | Right inner margin in points. |
margin_top | float | Read/Write | Top inner margin in points (default ~3.6 pt). |
margin_bottom | float | Read/Write | Bottom inner margin in points. |
text_anchor_type | TextAnchorType | Read/Write | Vertical anchor: TOP, CENTER, BOTTOM, JUSTIFIED, DISTRIBUTED. |
text_vertical_type | TextVerticalType | Read/Write | Text direction: HORIZONTAL, VERTICAL, VERTICAL270. |
anchor_center | bool | Read/Write | Centre text box horizontally inside the cell. |
col_span | int | Read | Number of columns spanned (1 = not merged). |
row_span | int | Read | Number of rows spanned (1 = not merged). |
is_merged_cell | bool | Read | True if this cell participates in a merge. |
first_row_index | int | Read | Zero-based row index of this cell. |
first_column_index | int | Read | Zero-based column index of this cell. |
width | float | Read | Cell width in points (sum of spanned column widths). |
height | float | Read | Cell height in points (sum of spanned row heights). |
offset_x | float | Read | Distance from the table left edge to this cell’s left edge, in points. |
offset_y | float | Read | Distance from the table top edge to this cell’s top edge, in points. |
table | Table | Read | The parent Table. |
first_row | Row | Read | The Row that contains this cell. |
first_column | Column | Read | The Column that contains this cell. |
CellCollection
Collection of Cell objects belonging to a Row.
| Member | Description |
|---|---|
__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
| Property | Type | Access | Description |
|---|---|---|---|
width | float | Read/Write | Column width in points. |
column_format | ColumnFormat | Read | Column-level formatting object. |
ColumnCollection
Collection of Column objects belonging to a Table.
| Member | Description |
|---|---|
__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)