Create and Manipulate Tables in PowerPoint Java

Tables are used to well organize the data in the form of rows and columns. Moreover, they summarize the data to be viewed and analyzed easily. MS PowerPoint also allows the presenters to create tables in the presentations. Accordingly, in this article, you will learn how to create and manipulate tables in PowerPoint presentations using Java.

Java API to Create and Manipulate Tables in PowerPoint PPT

To create and manipulate tables in PowerPoint presentations, we will use Aspose.Slides for Java. The API is designed to create, manipulate and convert PowerPoint and OpenOffice presentations. You can download the API’s JAR or install it using the following Maven configurations.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>21.8</version>
    <classifier>jdk16</classifier>
</dependency>

Create a Table in PowerPoint PPT using Java

Creating a table using Aspose.Slides for Java is as easy as a pie. The following steps demonstrate how to create a table in a PowerPoint PPT from scratch in Java.

The following code sample shows how to add a table in a PowerPoint PPT in Java.

The following screenshot shows the table that we have created using the above code.

Create Table in PowerPoint Java

Access a Table in a PPT using Java

You can also access the tables in the existing PowerPoint presentations and manipulate them as required. The following are the steps to access the tables in a presentation.

The following code sample shows how to access tables in a PowerPoint presentation using Java.

Format Text in PowerPoint Tables using Java

Aspose.Slides for Java also allows you to set formatting of the tables quite easily, as demonstrated in the steps below.

The following code sample shows how to set the formatting of the table in PowerPoint using Java.

Lock Aspect Ratio of Tables in PPTX using Java

You can also lock the aspect ratio of the tables in PowerPoint PPT using Java. The following are the steps to achieve this.

  • First, load an existing presentation using Presentation class.
  • Get reference of the desired slide into an ISlide object.
  • Create a table or retrieve the reference of existing table into an ITable object.
  • Lock the aspect ratio using ITable.getGraphicalObjectLock().setAspectRatioLocked(!ITable.getGraphicalObjectLock().getAspectRatioLocked()) method.
  • Finally, save the presentation using Presentation.save(String, SaveFormat) method.

The following Java code sample shows how to lock the aspect ratio of the table in PowerPoint PPTX.

Java API to Create PowerPoint Tables - Get a Free License

You can use Aspose.Slides for Java without evaluation limitations by getting a free temporary license.

Conclusion

In this article, you have learned how to create tables in PowerPoint PPT using Java. Moreover, you have seen how to access the tables and set their formatting and aspect ratio programmatically. In addition, you can visit the documentation to explore more about Aspose.Slides for Java. Also, you can ask your questions via our forum.

See Also