Create and Manipulate Tables in PowerPoint C#

Tables are used to arrange the data in the form of rows and columns. Moreover, they organize and summarize the data so that it can be viewed and analyzed easily. MS PowerPoint also allows you to insert tables in the presentations. Accordingly, this article covers how to create and manipulate tables in PowerPoint presentations using C#.

C# API to Create and Manipulate Tables in PowerPoint

To create and manipulate tables in PowerPoint presentations, we will use Aspose.Slides for .NET. The API lets you create, manipulate and convert PowerPoint and OpenOffice documents. You can download the API’s DLL and add a reference to it in your project. Also, you can install it using NuGet.

PM> Install-Package Aspose.Slides.NET

Create a Table in PowerPoint Presentations using C#

Creating a table using Aspose.Slides for .NET is a piece of cake. The following steps show how to create a table in a PowerPoint presentation using C#.

  • First, create a new presentation or load an existing one using Presentation class.
  • Then, get reference of the desired slide into an ISlide object.
  • Define the width and height of columns and rows respectively in double[] arrays.
  • Insert a new table in presentation using ISlide.Shapes.AddTable() method.
  • Get reference of the newly created table in an ITable object.
  • Create a loop to iterate through the rows of the table.
  • Create a nested loop to iterate through the cells of the table and in each iteration, perform the following operations.
  • Finally, save the presentation using Presentation.Save(String, SaveFormat) method.

The following code sample shows how to create a table in a PowerPoint presentation.

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

Create Table in PowerPoint C#

Access a Table in a Presentation using C#

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 C#.

Format Text in PowerPoint Tables using C#

Aspose.Slides for .NET 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 C#.

Lock Aspect Ratio of Tables in PowerPoint using C#

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

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

Get a Free API License

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

Conclusion

In this article, you have learned how to create tables in PowerPoint presentations using C#. Moreover, you have seen how to access and manipulate existing tables in the PowerPoint presentations programmatically. In addition, you can visit the documentation to explore more about Aspose.Slides for .NET. Also, you can ask your questions via our forum.

See Also