If you are preparing a large number of presentations, cloning slides can help you save resources. Instead of creating new slides from scratch for each presentation, it is more efficient and less time-consuming to modify existing slides. In this article, you will learn how to copy slides in PowerPoint presentations in C# using Spire.Presentation for .NET.
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
Copy Slides Within the Same Presentation in C#
You can clone a slide either at a specified location or at the end of a PowerPoint presentation through the Presentation.Slides.Insert(intIndex, ISlide slide) or Presentation.Slides.Append(ISlide slide) methods. The following are the detailed steps.
- Create a Presentation instance.
- Load a PowerPoint presentation using Presentation.LoadFromFile() method.
- Get a specified slide using Prenstion.Slides[] property.
- Clone the slide to the end of the same presentation using Presentation.Slides.Append() method.
- Clone the slide to a specific position within the same presentation using Presentation.Slides.Insert() method.
- Save the result file using Presentation.SaveToFile() method.
- C#
using Spire.Presentation; namespace CopySlides { class Program { static void Main(string[] args) { //Create a Presentation instance Presentation ppt = new Presentation(); //Load a PowerPoint presentation ppt.LoadFromFile("Input1.pptx"); //Get the first slide in the presentation ISlide slide = ppt.Slides[0]; //Clone the slide to the end of the presentation ppt.Slides.Append(slide); //Clone the slide to the third position within the presentation ppt.Slides.Insert(2, slide); //Save the result file ppt.SaveToFile("CloneSlidesWithinTheSame.pptx", FileFormat.Pptx2013); } } }
Copy Slides to Another Presentation in C#
Spire.Presentation for .NET also allows you to load two PowerPoint files and then clone the slides from one presentation to another presentation. The following are the detailed steps.
- Create a Presentation instance.
- Load two PowerPoint presentations using Presentation.LoadFromFile() method.
- Get two slides in the first presentation using Prenstion.Slides[] property.
- Clone the first slide to a specific position in the second presentation using Presentation.Slides.Insert() method.
- Clone the second slide to the end of the second presentation using Presentation.Slides.Append() method.
- Save the result file using Presentation.SaveToFile() method.
- C#
using Spire.Presentation; namespace CopySlidesToAnother { class Program { static void Main(string[] args) { //Load the first PowerPoint presentation Presentation sourcePPT = new Presentation(); sourcePPT.LoadFromFile("Input1.pptx"); //Load the second PowerPoint presentation Presentation destPPT = new Presentation(); destPPT.LoadFromFile("Input2.pptx"); //Get two slides in the first presentation ISlide slide1 = sourcePPT.Slides[1]; ISlide slide2 = sourcePPT.Slides[2]; //Clone slide1 to the second position in the second presentation destPPT.Slides.Insert(1, slide1); //Clone slide2 to the end of the second presentation destPPT.Slides.Append(slide2); //Save the result file destPPT.SaveToFile("CloneSlidesToAnother.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.