Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 30, 2021 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/724b75c8a9bfaec816cedc23d3db0768 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/724b75c8a9bfaec816cedc23d3db0768 to your computer and use it in GitHub Desktop.
Clone Slides in PowerPoint Presentations using C++
// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\CloneSlideAtEnd_out.pptx";
// Load the presentation
auto presentation = System::MakeObject<Presentation>(sourceFilePath);
// Retrieve the slides
auto slides = presentation->get_Slides();
// Add the slide clone
slides->AddClone(presentation->get_Slides()->idx_get(0));
// Save the presentation
presentation->Save(outputFilePath, SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String destinationFilePath = u"SourceDirectory\\Slides\\SamplePresentation2.pptx";
const String outputFilePath = u"OutputDirectory\\CloneSlideToOtherPresentationAtEnd_out.pptx";
// Load the source presentation
auto sourcePresentation = System::MakeObject<Presentation>(sourceFilePath);
// Load the destination presentation
auto destinationPresentation = System::MakeObject<Presentation>(destinationFilePath);
// Get the slides of the destination presentation
auto destinationSlides = destinationPresentation->get_Slides();
// Add slide from the source presentation to the end of the destination presentation
destinationSlides->AddClone(sourcePresentation->get_Slides()->idx_get(0));
// Save the destination presentation
destinationPresentation->Save(outputFilePath, SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String outputFilePath = u"OutputDirectory\\CloneSlideAtSpecificIndex_out.pptx";
// Load the presentation
auto presentation = System::MakeObject<Presentation>(sourceFilePath);
// Retrieve the slides
auto slides = presentation->get_Slides();
// Insert the clone at 0 index
slides->InsertClone(0, presentation->get_Slides()->idx_get(1));
// Save the presentation
presentation->Save(outputFilePath, SaveFormat::Pptx);
// File paths
const String sourceFilePath = u"SourceDirectory\\Slides\\SamplePresentation.pptx";
const String destinationFilePath = u"SourceDirectory\\Slides\\SamplePresentation2.pptx";
const String outputFilePath = u"OutputDirectory\\CloneSlideToOtherPresentationAtSpecificIndex_out.pptx";
// Load the source presentation
auto sourcePresentation = System::MakeObject<Presentation>(sourceFilePath);
// Load the destination presentation
auto destinationPresentation = System::MakeObject<Presentation>(destinationFilePath);
// Get the slides of the destination presentation
auto destinationSlides = destinationPresentation->get_Slides();
// Insert slide from the source presentation to the 2nd index of the destination presentation
destinationSlides->InsertClone(2, sourcePresentation->get_Slides()->idx_get(0));
// Save the destination presentation
destinationPresentation->Save(outputFilePath, SaveFormat::Pptx);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment