Slides are the most basic component of a PowerPoint document. Each PowerPoint presentation can be composed of a series of slides containing different elements, such as text, shapes, tables, and images. When you are working on a PowerPoint document, adding and removing slides are probably some of the most required actions. In this article, you will learn how to programmatically add or delete a PowerPoint slide using Spire.Presentation for .NET.
- Add a New Slide at the End of the PowerPoint Document
- Insert a New Slide Before a Specific Slide in PowerPoint
- Delete a Specific Slide from a PowerPoint Document
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 a New Slide at the End of the PowerPoint Document
The Presentation.Slides.Append() method provided by Spire.Presentation for .NET allows you to append a new slide after the last slide of a PowerPoint document. The detailed steps are as follows.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Add a new blank slide at the end of the document using Presentation.Slides.Append() method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; namespace AddNewSlideinPowerPoint { class Program { static void Main(string[] args) { // Initialize an instance of Presentation class Presentation presentation = new Presentation(); //Load a sample PowerPoint document presentation.LoadFromFile("Sample.pptx"); //Add a new slide at the end of the document presentation.Slides.Append(); //Save the result document presentation.SaveToFile("AddSlide.pptx", FileFormat.Pptx2013); } } }
Insert a New Slide Before a Specific Slide in PowerPoint
Sometimes you may also need to insert a slide before a specific slide to add additional supporting information, and below are the detailed steps to accomplish the task.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Insert a blank slide before a specified slide using Presentation.Slides.Insert() method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; namespace InsertSlideinPowerPoint { class Program { static void Main(string[] args) { //Create a Presentation object Presentation presentation = new Presentation(); //Load a sample PowerPoint document presentation.LoadFromFile("Sample.pptx"); //Insert a blank slide before the second slide presentation.Slides.Insert(1); //Save the result document presentation.SaveToFile("InsertSlide.pptx", FileFormat.Pptx2013); } } }
Delete a Specific Slide from a PowerPoint Document
If you want to remove a unnecessary slide from the document, you can use the Presentation.Slides.RemoveAt(int index) method. The detailed steps are as follows.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Remove a specified slide from the document using Presentation.Slides.RemoveAt() method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; namespace DeletePowerPointSlide { class Program { static void Main(string[] args) { //Create a Presentation object Presentation presentation = new Presentation(); //Load a sample PowerPoint document presentation.LoadFromFile("Sample.pptx"); //Remove the first slide presentation.Slides.RemoveAt(0); //Save the result document presentation.SaveToFile("RemoveSlide.pptx", FileFormat.Pptx2013); } } }
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.