Displaying PowerPoint text box content in multiple columns significantly enhances the presentation of information and audience comprehension. It improves readability by shortening line lengths, making dense text more digestible; optimizes visual layout for an aesthetically pleasing and professional look; and utilizes space efficiently to ensure that information is abundant yet uncluttered. In this article, we will introduce how to add or remove columns in a PowerPoint text box using Spire.Presentation for .NET in C# projects.
Install Spire.Presentation for .NET
To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Presentation
Add Columns to a PowerPoint Text Box with C#
Spire.Presentation provides the Shape.TextFrame.ColumnCount property to set the number of columns for content and the Shape.TextFrame.ColumnSpacing property to set the spacing between columns. Below are the detailed steps:
- Create a Presentation object.
- Load a PowerPoint document using the Presentation.LoadFromFile() method.
- Retrieve the first slide using Presentation.Slides[0].
- Obtain the first text box object as IAutoShape.
- Use the Shape.TextFrame.ColumnCount property to set the number of columns for the text box content.
- Use the Shape.TextFrame.ColumnSpacing property to set the spacing between columns.
- Save the document to a specified path using the Presentation.SaveToFile() method.
- C#
using Spire.Presentation; namespace Spire.PresentationDemo { internal class Program { static void Main(string[] args) { // Create a Presentation object Presentation presentation = new Presentation(); // Load the PPTX file presentation.LoadFromFile("Sample1.pptx"); // Get the first slide ISlide slide = presentation.Slides[0]; // Check if the first shape on the slide is of type IAutoShape if (slide.Shapes[0] is IAutoShape) { // Cast the first shape to an IAutoShape object IAutoShape shape = (IAutoShape)slide.Shapes[0]; // Set the number of columns in the shape's text frame to 2 shape.TextFrame.ColumnCount = 2; // Set the column spacing in the shape's text frame to 25 pt shape.TextFrame.ColumnSpacing = 25f; } // Save the modified presentation as a new PPTX file presentation.SaveToFile("SetColumns.pptx", Spire.Presentation.FileFormat.Pptx2016); // Dispose of the resources used by the Presentation object presentation.Dispose(); } } }
Remove Columns from a PowerPoint Text Box with C#
To remove the columns from the Powerpoint text box, simply set the Shape.TextFrame.ColumnCount property to 1. Below are the detailed steps:
- Create a Presentation object.
- Load a PowerPoint document using the Presentation.LoadFromFile() method.
- Retrieve a slide using the Presentation.Slides[index] property.
- Obtain the text box object as IAutoShape.
- Set Shape.TextFrame.ColumnCount = 1 to remove the columns.
- Save the document to a specified path using the Presentation.SaveToFile() method.
- C#
using Spire.Presentation; namespace SpirePresentationDemo { internal class Program { static void Main(string[] args) { // Create a Presentation object Presentation presentation = new Presentation(); // Load the PPTX file presentation.LoadFromFile("Sample2.pptx"); // Get the first slide ISlide slide = presentation.Slides[0]; // Check if the first shape on the slide is of type IAutoShape if (slide.Shapes[0] is IAutoShape) { // Cast the first shape to an IAutoShape object IAutoShape shape = (IAutoShape)slide.Shapes[0]; // Set the column count of the shape's text frame to 1 shape.TextFrame.ColumnCount = 1; } // Save the modified presentation as a new PPTX file presentation.SaveToFile("RemoveColumns.pptx", Spire.Presentation.FileFormat.Pptx2016); // Dispose of the resources used by the Presentation object presentation.Dispose(); } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.