Microsoft PowerPoint provides the ability to insert tables in PowerPoint presentations. Tables allow you to arrange data in the form of rows and columns. Furthermore, they organize the data and make it easy to view and analyze it. To that end, this article will teach you how to create and manipulate tables in PowerPoint presentations using C++.
- C++ API for Creating and Manipulating Tables in PowerPoint Presentations
- Create a Table in PowerPoint Presentations using C++
- Access and Modify a Table in PowerPoint Presentations using C++
- Set Text Direction in a PowerPoint Table using C++
C++ API for Creating and Manipulating Tables in PowerPoint Presentations
We will use the Aspose.Slides for C++ API to create and manipulate tables in PowerPoint presentations. It is a powerful and feature-rich API that supports creating, reading, and modifying PowerPoint files without needing Mircosoft PowerPoint to be installed. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Slides.Cpp
Create a Table in PowerPoint Presentations using C++
The following are the steps to create a table in PowerPoint presentations.
- Firstly, create an instance of the Presentation class to represent a new PowerPoint file.
- Retrieve the slide where you want to add the table.
- In an array, define the width and height of the table.
- Create the table using the ISlide->get_Shapes()->AddTable(float x, float y, System::ArrayPtr columnWidths, System::ArrayPtr rowHeights) method.
- Create a loop to iterate through the rows of the table.
- Within the loop, create a nested loop to iterate through the cells of each row.
- Format the cells according to your requirements.
- Finally, save the presentation using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code shows how to create a table in a PowerPoint presentation using C++.
Access and Modify a Table in PowerPoint Presentations using C++
You can also access and modify existing tables in PowerPoint presentations. The following are the steps to access and modify a table in PowerPoint presentations.
- Firstly, load the PowerPoint file using the Presentation class.
- Retrieve the slide containing the table.
- Iterate through the shapes of the slides.
- If the shape is of the type ITable, cast it as ITable and store it in a variable.
- Update the text of the table using the ITable->idx_get(int32_t columnIndex, int32_t rowIndex)->get_TextFrame()->set_Text(System::String value) method.
- Finally, save the presentation using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code shows how to access and modify a table in a PowerPoint presentation using C++.
Set Text Direction in a PowerPoint Table using C++
The following are the steps to set the direction of text in PowerPoint tables.
- Firstly, load the PowerPoint file using the Presentation class.
- Retrieve the slide containing the table.
- Iterate through the shapes of the slides.
- If the shape is of the type ITable, cast it as ITable and store it in a variable.
- Access the desired cell of the table in an ICell object using the ITable->idx_get(int32_t columnIndex, int32_t rowIndex) method.
- Set the text anchor type using the ICell->set_TextAnchorType(Aspose::Slides::TextAnchorType value) method.
- Set the text direction using the ICell->set_TextVerticalType(Aspose::Slides::TextVerticalType value) method.
- Finally, save the presentation using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code shows how to set the direction of text in a PowerPoint table using C++.
Get a Free License
In order to try the API without evaluation limitations, you can request a free temporary license.
Conclusion
In this article, you have learned how to create and update tables in PowerPoint presentations. Furthermore, you have seen how to set the direction of the text in PowerPoint tables using Aspose.Slides for C++ API. It is a robust API that provides a bunch of additional features for working with PowerPoint files. You can explore the API in detail by visiting the official documentation. In case of any queries, please feel free to reach us at our free support forum.