With Spire.Presentation, developers can easily add a new slide, duplicate a slide and delete a slide from the presentation. This article will show you how to copy a slide in PowerPoint documents. We will show you how to clone a slide in two ways:
- Cloning a slide from one position to another position within the same presentation.
- Cloning a slide from another presentation to a specified position.
Here comes to the steps of how to clone a slide in the presentation within the same PowerPoint document or from the different PowerPoint document.
Step 1: Create a PPT document and load the document from file.
Presentation ppt = new Presentation(); ppt.LoadFromFile("sample.pptx");
Step 2: Define the slide that will be cloned from the same presentation or from another presentation.
Duplicate the slides from the same presentation:
//Get a list of slides and choose the first slide to be cloned ISlide slide = ppt.Slides[0];
Duplicate the slides from the different presentation:
//Load the document from files and choose the first slide to be cloned. Presentation ppt1 = new Presentation(); ppt1.LoadFromFile("table.pptx"); ISlide slide = ppt1.Slides[0];
Step 3: Insert the desired slide to the specified index in the same presentation.
int index = 1; ppt.Slides.Insert(index, slide);
Step 4: Save and launch to view the PPTX document.
ppt.SaveToFile("result.pptx", Spire.Presentation.FileFormat.Pptx2010); System.Diagnostics.Process.Start("result.pptx");
Effective screenshot of duplicate a slide within the same presentation:
Effective screenshot of duplicate a slide from the different presentation:
Full codes:
using Spire.Presentation; namespace Dublicate { class Program { static void Main(string[] args) { Presentation ppt = new Presentation(); ppt.LoadFromFile("sample.pptx"); //Get a list of slides and choose the first slide to be cloned. ISlide slide = ppt.Slides[0]; ////Load the document from files and choose the first slide to be cloned. //Presentation ppt1 = new Presentation(); //ppt1.LoadFromFile("table.pptx"); //ISlide slide = ppt1.Slides[0]; int index = 1; ppt.Slides.Insert(index, slide); ppt.SaveToFile("result.pptx", Spire.Presentation.FileFormat.Pptx2010); System.Diagnostics.Process.Start("result.pptx"); } } }