Table
Contents
[
Hide
]
Examples for adding tables, accessing them, removing them, and merging cells using Aspose.Slides for Python via Java.
Install the package as described in Installation. Each example imports asposeslides before starting the JVM, then imports the API after the JVM is running.
Add a Table
Create a simple table with two rows and two columns.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
widths = jpype.JArray(jpype.JDouble)([80, 80])
heights = jpype.JArray(jpype.JDouble)([30, 30])
table = slide.getShapes().addTable(50, 50, widths, heights)
finally:
presentation.dispose()
Access a Table
Retrieve the first table shape on the slide.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, Table
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
widths = jpype.JArray(jpype.JDouble)([80, 80])
heights = jpype.JArray(jpype.JDouble)([30, 30])
table = slide.getShapes().addTable(50, 50, widths, heights)
# Access the first table on the slide.
first_table = None
for index in range(slide.getShapes().size()):
shape = slide.getShapes().get_Item(index)
if isinstance(shape, Table):
first_table = shape
break
finally:
presentation.dispose()
Remove a Table
Delete a table from a slide.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
widths = jpype.JArray(jpype.JDouble)([80, 80])
heights = jpype.JArray(jpype.JDouble)([30, 30])
table = slide.getShapes().addTable(50, 50, widths, heights)
slide.getShapes().remove(table)
finally:
presentation.dispose()
Merge Table Cells
Merge adjacent cells of a table into a single cell.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
widths = jpype.JArray(jpype.JDouble)([80, 80])
heights = jpype.JArray(jpype.JDouble)([30, 30])
table = slide.getShapes().addTable(50, 50, widths, heights)
# Merge cells.
table.mergeCells(table.get_Item(0, 0), table.get_Item(1, 1), False)
finally:
presentation.dispose()