# Table

> Create and format tables in PHP with Aspose.Slides: insert data, merge cells, style borders, align content, and import/export for PPT, PPTX and ODP.

Source: https://docs.aspose.com/slides/php-java/examples/elements/table/
Updated: 2026-02-20


Examples for adding tables, accessing them, removing them, and merging cells using **Aspose.Slides for PHP via Java**.

## **Add a Table**

Create a simple table with two rows and two columns.

```php
function addTable() {
    $presentation = new Presentation();
    try {
        $slide = $presentation->getSlides()->get_Item(0);

        $widths = [80, 80];
        $heights = [30, 30];
        $table = $slide->getShapes()->addTable(50, 50, $widths, $heights);

        $presentation->save("table.pptx", SaveFormat::Pptx);
    } finally {
        $presentation->dispose();
    }
}
```

## **Access a Table**

Retrieve the first table shape on the slide.

```php
function accessTable() {
    $presentation = new Presentation("table.pptx");
    try {
        $slide = $presentation->getSlides()->get_Item(0);

        // Access the first table on the slide.
        $firstTable = null;
        $shapeCount = java_values($slide->getShapes()->size());
        for ($index = 0; $index < $shapeCount; $index++) {
            $shape = $slide->getShapes()->get_Item($index);
            if (java_instanceof($shape, new JavaClass("com.aspose.slides.Table"))) {
                $firstTable = $shape;
                break;
            }
        }
    } finally {
        $presentation->dispose();
    }
}
```

## **Remove a Table**

Delete a table from a slide.

```php
function removeTable() {
    $presentation = new Presentation("table.pptx");
    try {
        $slide = $presentation->getSlides()->get_Item(0);

        // Assuming the table is the first shape on the slide.
        $table = $slide->getShapes()->get_Item(0);

        $slide->getShapes()->remove($table);

        $presentation->save("table_removed.pptx", SaveFormat::Pptx);
    } finally {
        $presentation->dispose();
    }
}
```

## **Merge Table Cells**

Merge adjacent cells of a table into a single cell.

```php
function mergeTableCells() {
    $presentation = new Presentation("table.pptx");
    try {
        $slide = $presentation->getSlides()->get_Item(0);

        // Assuming the table is the first shape on the slide.
        $table = $slide->getShapes()->get_Item(0);

        $table->mergeCells($table->get_Item(0, 0), $table->get_Item(1, 1), false);

        $presentation->save("cells_merged.pptx", SaveFormat::Pptx);
    } finally {
        $presentation->dispose();
    }
}
```



## Related articles

- [Create and Customize PowerPoint Tables in PHP](https://docs.aspose.com/slides/php-java/powerpoint-table/)
- [Manage Table Cells in Presentations Using PHP](https://docs.aspose.com/slides/php-java/manage-cells/)
- [Manage Presentation Tables in PHP](https://docs.aspose.com/slides/php-java/manage-table/)