How to Create/Read/Edit PowerPoint in C# Using WinForms Presentation?
The following steps demonstrate how to create, read, and edit PowerPoint slides in a Windows Forms application using the WinForms 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 a slide to the PowerPoint
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
// Adds a textbox to the slide
IShape textboxShape = slide.AddTextBox(0, 0, 500, 500);
// Adds a paragraph to the text body of the textbox
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 the Presentation
ISlide slide = pptxDoc.Slides[0];
// Gets the shape in the slide
IShape textboxShape = slide.Shapes[0] as IShape;
// Gets an instance of a paragraph in the textbox
IParagraph paragraph = textboxShape.TextBody.Paragraphs[0];
// Reads 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
Conclusion
I hope you enjoyed learning how to create, read, and edit PowerPoint files in C# using WinForms Presentation.
You can refer to the WinForms Presentation feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our WinForms Presentation example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!