Table
Contents
[
Hide
]
Examples for adding tables, accessing them, removing them, and merging cells using Aspose.Slides for Python via .NET.
Add a Table
Create a simple table with two rows and two columns.
def add_table():
with slides.Presentation() as presentation:
slide = presentation.slides[0]
# Define column widths and row heights.
widths = [80, 80]
heights = [30, 30]
# Add a table shape to the slide.
table = slide.shapes.add_table(50, 50, widths, heights)
presentation.save("table.pptx", slides.export.SaveFormat.PPTX)
Access a Table
Retrieve the first table shape on the slide.
def access_table():
with slides.Presentation("table.pptx") as presentation:
slide = presentation.slides[0]
# Access the first table on the slide.
first_table = next(shape for shape in slide.shapes if isinstance(shape, slides.Table))
Remove a Table
Delete a table from a slide.
def remove_table():
with slides.Presentation("table.pptx") as presentation:
slide = presentation.slides[0]
# Assuming the first shape is a table.
table = slide.shapes[0]
# Remove the table from the slide.
slide.shapes.remove(table)
presentation.save("table_removed.pptx", slides.export.SaveFormat.PPTX)
Merge Table Cells
Merge adjacent cells of a table into a single cell.
def merge_table_cells():
with slides.Presentation("table.pptx") as presentation:
slide = presentation.slides[0]
# Assuming the first shape is a table.
table = slide.shapes[0]
# Merge cells.
table.merge_cells(table.rows[0][0], table.rows[1][1], False)
presentation.save("cells_merged.pptx", slides.export.SaveFormat.PPTX)