Copy a paragraph from one presentation slide to another in C#

In our daily work, we may need to copy the contents from one presentation slides to another. This article is aimed to introduce the method of how to copy the content from one paragraph from the source PowerPoint document to the target document by using Spire.Presenation.

Firstly, View the original presentation slide and the target presentation slide.

Copy a paragraph from one presentation slide to another in C#

Step 1: Initialize an instances of Presentation class and load the source document from file

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

Step 2: Get the text from the first shape on the first slide.

string Text = "";           
IShape shp = ppt.Slides[0].Shapes[0];
Text = ((IAutoShape)shp).TextFrame.Text;

Step 3: Get the first shape on the first slide from the target document file.

Presentation ppt2 = new Presentation("Sample1.pptx", FileFormat.Pptx2010);
IShape destshp = ppt2.Slides[0].Shapes[0];

Step 4: Get text from placeholder.

((IAutoShape)destshp).TextFrame.Text += Text;

Step 5: Save the document to file.

ppt2.SaveToFile("Sample1.pptx", FileFormat.Pptx2010);

Effective screenshot after copy the paragraph from the source file:

Copy a paragraph from one presentation slide to another in C#

Full codes:

{
    Presentation ppt = new Presentation();
    ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

    string Text = "";
    IShape shp = ppt.Slides[0].Shapes[0];
    Text = ((IAutoShape)shp).TextFrame.Text;
   
    Presentation ppt2 = new Presentation("Sample1.pptx", FileFormat.Pptx2010);
    IShape destshp = ppt2.Slides[0].Shapes[0];
    ((IAutoShape)destshp).TextFrame.Text += Text;
    
    ppt2.SaveToFile("Sample1.pptx", FileFormat.Pptx2010);
}