Create PowerPoint Presentations C#

MS PowerPoint presentations allow you to create slide shows containing text, images, charts, animations, and other elements. Various additional formatting options let you make your presentations more appealing. In this post, you will come to know how to create PowerPoint PPT PPTX in C#. You will learn how to insert text, tables, images, and charts in PowerPoint PPT in programmatically in C#.

C# API to Create PowerPoint PPT - Free Download

Aspose.Slides for .NET is a presentation manipulation API that lets you create and manipulate PowerPoint documents from within your .NET applications. The API provides nearly all possible features required to implement basic as well as advanced PowerPoint automation features. You can either download the API or install it via NuGet.

Install-Package Aspose.Slides.NET

Create a PowerPoint PPT in C#

Let’s start by creating an empty PowerPoint PPT/PPTX presentation using Aspose.Slides for .NET. The following are the steps to do so.

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

Open an Existing PowerPoint Presentation in C#

You don’t need to put extra efforts in order to open an existing PowerPoint presentation. Simply provide the path of the PPTX file to the constructor of the Presentation class and you are done. The following code sample shows how to open an existing PPTX presentation.

Add a Slide to PPT in C#

Once you have created the presentation, you can start adding the slides to it. The following are the steps to add a slide in the presentation using Aspose.Slides for .NET.

The following code sample shows how to add a slide in a PowerPoint presentation using C#.

Insert Text in a PPT Slide using C#

Now we can add content to the slides in the PowerPoint presentation. Let’s first add a piece of text to the slide using the following steps.

  • Create a new presentation using the Presentation class.
  • Obtain the reference of the slide in the presentation.
  • Add an IAutoShape with ShapeType as Rectangle at a specified position of the slide.
  • Obtain the reference of that newly added IAutoShape object.
  • Add a TextFrame to the AutoShape containing the default text.
  • Save the presentation as a PPTX file.

The following code sample shows how to add text to slide in a presentation using C#.

Create Table in a PPT Presentation using C#

Aspose.Slides for .NET provides an easy way to create a table in the presentation document. The following are the steps for it.

  • Create an instance of the Presentation class.
  • Obtain the reference of a slide by using its index.
  • Define arrays of columns with width and rows with height.
  • Add a table to the slide using Slide.Shapes.AddTable() method exposed by IShapes object and get the reference to the table in ITable instance.
  • Iterate through each cell to apply the formatting.
  • Add text to the cells using Table.Rows[][].TextFrame.Text property.
  • Save the presentation as a PPTX file.

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

Create Chart in a PowerPoint PPT using C#

The following are the steps to add a chart in PowerPoint presentation using C#.

  • Create an instance of the Presentation class.
  • Obtain the reference of a slide by index.
  • Add a chart with the desired type using ISlide.Shapes.AddChart(ChartType, Single, Single, Single, Single) method.
  • Add a chart title.
  • Access the chart data worksheet.
  • Clear all the default series and categories.
  • Add new series and categories.
  • Add new chart data for chart series.
  • Set fill color for chart series.
  • Add chart series labels.
  • Save the presentation as a PPTX file.

The following code sample shows how to add chart in a presentation using C#.

Learn more about the presentation charts here.

Add an Image in PowerPoint Presentation

The following are the steps to add images in the presentation slide.

The following code sample shows how to add image to a presentation in C#.

C# .NET PowerPoint API - Get a Free 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 PowerPoint PPT presentations from scratch using C#. In addition, you have seen how to add slides, text, tables, images, and charts in new or existing PPTX presentations. You can learn more about the API using the documentation.

See Also

Tip: Besides the creation of slides or presentations, Aspose.Slides provides many features that allow you to work with presentations. For example, using its own APIs, Aspose developed a free online viewer for Microsoft PowerPoint Presentations.