Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
From the office to the classroom, Microsoft PowerPoint is a staple. With decades of improvements, it’s an industry-standard presentation tool for a reason. However, making the most of your PowerPoint presentation can be complex and time-consuming.
In this guide, we’ll explain how you can automate the creation of a PowerPoint presentation, optimize processes, and fully utilize the program thanks to the flexibility of C# (C Sharp) and the Microsoft PowerPoint interop library.
First of all, let's learn the fundamentals of PowerPoint interop before delving into the nuances of making PowerPoint documents with C#. Developers can create presentations, add slides, add content, apply formatting, and more with the help of the PowerPoint interop library, giving you more flexibility when creating a new presentation. This way, developers can customize their presentation file to meet unique requirements and access a wealth of functions.
Creating a PowerPoint presentation in C# allows you to create reports on the fly and convert presentations to other formats. You can download interop libraries for free, but you’ll need Microsoft Office installed to create a PowerPoint presentation programmatically.
We begin by creating a new console application project in Visual Studio. Go to File and select New Project. Choose the C# language and select Console Application. Enter your project name, choose the location you want to save it to, and hit the Next button. Select the latest .NET Framework and then Create. Once your project is up and running, it’s time to add our library.
You can create, open, and modify your PowerPoint document directly within your C# project using the Microsoft.Office.interop.PowerPoint.Application class. Here’s what the code looks like:
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
class Program
{
static void Main(string[] args)
{
// Create an instance of PowerPoint application
PowerPoint.Application powerpointApp = new PowerPoint.Application();
// Create powerpoint presentation
PowerPoint.Presentation presentation = powerpointApp.Presentations.Add();
// Customize the presentation
// Add slides, insert content, apply formatting, etc.
// Add a new slide
PowerPoint.Slide slide = presentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitle);
// Insert text into the presentation slide
slide.Shapes[1].TextFrame.TextRange.Text = "Demo";
slide.Shapes[2].TextFrame.TextRange.Text = "PowerPoint";
// Add an image to the slide
slide.Shapes.AddPicture(@"sample.png",
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoCTrue,
100, 100, 300, 200);
// Save and close the presentation file
presentation.SaveAs("Presentation.pptx");
presentation.Close();
// Quit PowerPoint application
powerpointApp.Quit();
Console.ReadKey();
}
}
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
class Program
{
static void Main(string[] args)
{
// Create an instance of PowerPoint application
PowerPoint.Application powerpointApp = new PowerPoint.Application();
// Create powerpoint presentation
PowerPoint.Presentation presentation = powerpointApp.Presentations.Add();
// Customize the presentation
// Add slides, insert content, apply formatting, etc.
// Add a new slide
PowerPoint.Slide slide = presentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitle);
// Insert text into the presentation slide
slide.Shapes[1].TextFrame.TextRange.Text = "Demo";
slide.Shapes[2].TextFrame.TextRange.Text = "PowerPoint";
// Add an image to the slide
slide.Shapes.AddPicture(@"sample.png",
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoCTrue,
100, 100, 300, 200);
// Save and close the presentation file
presentation.SaveAs("Presentation.pptx");
presentation.Close();
// Quit PowerPoint application
powerpointApp.Quit();
Console.ReadKey();
}
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
You can alter newly constructed PowerPoint presentations to make it fit your requirements. Slides, text, photos, charts, chart title, and other multimedia items may be inserted, formatting may be applied, transitions and animations may be established, and other tasks may be involved. By utilizing the features offered by the PowerPoint interop library, you may programmatically adjust different parts of the presentation.
To save the PowerPoint document to a specific file location, use the SaveAs() method. To dismiss it, use the dismiss method.
Using C# to create PowerPoint presentations is an effective way to improve productivity, streamline processes, and save time. The Microsoft PowerPoint interop library's features may be utilized by developers to automate the production and customization of presentations, resulting in time and effort savings and professional outcomes when working with PowerPoint files.
Using this method can improve your presentation skills and help you engage your audience with visually striking slides, whether you're a presenter, educator, or business professional.
For more expansive document management and presentation creation options, explore Iron Software's range of tools, like IronPDF for PDF Manipulation and IronXL for Excel Automation. These tools integrate seamlessly with C# projects, offering enhanced functionality and streamlining your workflow.
9 .NET API products for your office documents