Articles in this section
Category / Section

Create, read and edit PowerPoint slides in C#

2 mins read

The following steps demonstrates how to create, read, and edit PowerPoint slides in a Windows forms application using the Presentation library.

 

Steps to create, read and edit PowerPoint slides Programmatically:

 

Step 1: Create a new Windows Forms application. Name it as GettingStarted.

Step 2: Install Presentation assemblies with NuGet

In Visual Studio, select Tools > NuGet Package Manager > Package Manager Console and execute the following command for the project.

install-package Syncfusion.Presentation.WinForms

Step 3: Add a new button to the form editor.


Step 4: Include the following code example in the click event of the button in Form.cs, to create a PowerPoint presentation and save it as a file.

//Creates PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Adds slide to the PowerPoint
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Adds textbox to the slide
IShape textboxShape = slide.AddTextBox(0, 0, 500, 500);
//Adds paragraph to the textbody of text box
IParagraph paragraph = textboxShape.TextBody.AddParagraph();
//Adds a TextPart to the paragraph
ITextPart textPart = paragraph.AddTextPart();
//Adds text to the TextPart
textPart.Text = "AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";
//Saves the Presentation
pptxDoc.Save("Output.pptx");
//Closes the Presentation
pptxDoc.Close();

 

Step 5: Include the following code example in the click event of the button in Form.cs, to read and edit a PowerPoint presentation and save it as a file.

//Loads the PowerPoint Presentation
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Gets the slide from Presentation
ISlide slide = pptxDoc.Slides[0];
//Gets the shape in slide
IShape textboxShape = slide.Shapes[0] as IShape;  
//Gets instance of a paragraph in a text box
IParagraph paragraph = textboxShape.TextBody.Paragraphs[0];
//Read the text in the paragraph
string text = paragraph.Text;
//Applies the first line indent of the paragraph
paragraph.FirstLineIndent = 10;
//Applies the horizontal alignment of the paragraph to center
paragraph.HorizontalAlignment = HorizontalAlignmentType.Left;
//Applies the left indent of the paragraph
paragraph.LeftIndent = 8;
//Saves the Presentation
pptxDoc.Save("Output.pptx");
//Closes the Presentation
pptxDoc.Close();

 

See Also:

Create a PowerPoint file in ASP.NET MVC

Create a PowerPoint file in ASP.NET

Create a PowerPoint file in Xamarin

Create a PowerPoint file in WPF

Create a PowerPoint file in UWP

Create a PowerPoint file in ASP.NET Core

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied