スライドのクローン
プレゼンテーション内のスライドをクローン
クローンとは、何かの正確なコピーまたは複製を作成するプロセスです。Aspose.Slides for C++を使用すると、任意のスライドのコピーまたはクローンを作成し、そのクローンスライドを現在のプレゼンテーションまたは他の開いているプレゼンテーションに挿入することができます。スライドのクローンを作成するプロセスでは、元のスライドを変更することなく、開発者が修正できる新しいスライドが作成されます。スライドをクローンする方法はいくつかあります:
- プレゼンテーション内の最後にクローン。
- プレゼンテーション内の別の位置にクローン。
- 別のプレゼンテーションの最後にクローン。
- 別のプレゼンテーションの別の位置にクローン。
- 別のプレゼンテーションの特定の位置にクローン。
Aspose.Slides for C++では、Presentationオブジェクトによって公開された(ISlideオブジェクトのコレクション)は、上記の種類のスライドクローンを実行するためのAddCloneおよびInsertCloneメソッドを提供します。
プレゼンテーション内の最後にクローン
スライドをクローンし、その既存のスライドの最後に同じプレゼンテーションファイル内で使用したい場合は、以下の手順に従ってAddCloneメソッドを使用します。
- Presentationクラスのインスタンスを作成します。
- Presentationオブジェクトによって公開されたスライドコレクションを参照して、ISlideCollectionクラスをインスタンス化します。
- ISlideCollectionオブジェクトによって公開されたAddCloneメソッドを呼び出し、クローン対象のスライドをAddCloneメソッドのパラメータとして渡します。
- 修正されたプレゼンテーションファイルを保存します。
以下の例では、プレゼンテーションの最初の位置(ゼロインデックス)にあるスライドをプレゼンテーションの最後にクローンしています。
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/AddSlides.pptx"; | |
const String outPath = u"../out/CloneWithinSamePresentationToEnd.pptx"; | |
// Instantiate Presentation class | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Accessing Slide by ID from collection | |
SharedPtr<ISlideCollection> slides = pres->get_Slides(); | |
// Clone the desired slide at end of same presentation | |
slides->AddClone(pres->get_Slides()->idx_get(0)); | |
// Writing the presentation file | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
プレゼンテーション内の別の位置にクローン
スライドをクローンし、同じプレゼンテーションファイル内で異なる位置に使用したい場合は、InsertCloneメソッドを使用します:
- Presentationクラスのインスタンスを作成します。
- Presentationオブジェクトによって公開されたSlidesコレクションを参照して、クラスをインスタンス化します。
- ISlideCollectionオブジェクトによって公開されたInsertCloneメソッドを呼び出し、新しい位置のインデックスとともにクローン対象のスライドをInsertCloneメソッドのパラメータとして渡します。
- 修正されたプレゼンテーションをPPTXファイルとして保存します。
以下の例では、プレゼンテーションのゼロインデックス(位置1)にあるスライドをインデックス1(位置2)にクローンしています。
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/AddSlides.pptx"; | |
const String outPath = u"../out/CloneWithInSamePresentation.pptx"; | |
// Instantiate Presentation class | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Accessing Slide by ID from collection | |
SharedPtr<ISlideCollection> slides = pres->get_Slides(); | |
// Clone the desired slide to the specified index in the same presentation | |
slides->InsertClone(2, pres->get_Slides()->idx_get(0)); | |
// Writing the presentation file | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
別のプレゼンテーションの最後にスライドをクローン
1つのプレゼンテーションからスライドをクローンし、他のプレゼンテーションファイルで使用したい場合、すなわち既存のスライドの後に:
- スライドをクローンするプレゼンテーションを含むPresentationクラスのインスタンスを作成します。
- スライドを追加する目的のプレゼンテーションを含むPresentationクラスのインスタンスを作成します。
- 目的のプレゼンテーションのPresentationオブジェクトによって公開されたSlidesコレクションを参照して、ISlideCollectionクラスをインスタンス化します。
- ISlideCollectionオブジェクトによって公開されたAddCloneメソッドを呼び出し、ソースプレゼンテーションからのスライドをAddCloneメソッドのパラメータとして渡します。
- 修正された目的のプレゼンテーションファイルを保存します。
以下の例では、ソースプレゼンテーションの最初のインデックスからスライドを目的のプレゼンテーションの最後にクローンしています。
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/AddSlides.pptx"; | |
const String outPath = u"../out/CloneAtEndOfAnotherPresentation.pptx"; | |
// Instantiate Presentation class | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
//Instantiate target presentation object | |
SharedPtr<Presentation> destPres = MakeObject<Presentation>(); | |
// Accessing Slide by ID from collection | |
SharedPtr<ISlideCollection> slideCollection = destPres->get_Slides(); | |
// Clone the desired slide at end of other presentation | |
slideCollection->AddClone(pres->get_Slides()->idx_get(0)); | |
// Writing the presentation file | |
destPres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
別のプレゼンテーションの別の位置にスライドをクローン
1つのプレゼンテーションからスライドをクローンし、別のプレゼンテーションファイルで特定の位置に使用したい場合:
- スライドをクローンするソースプレゼンテーションを含むPresentationクラスのインスタンスを作成します。
- スライドを追加するプレゼンテーションを含むPresentationクラスのインスタンスを作成します。
- 目的のプレゼンテーションのPresentationオブジェクトによって公開されたスライドコレクションを参照して、ISlideCollectionクラスをインスタンス化します。
- ISlideCollectionオブジェクトによって公開されたInsertCloneメソッドを呼び出し、ソースプレゼンテーションのスライドとともに希望の位置をInsertCloneメソッドのパラメータとして渡します。
- 修正された目的のプレゼンテーションファイルを保存します。
以下の例では、ソースプレゼンテーションのゼロインデックスからスライドを目的のプレゼンテーションのインデックス1(位置2)にクローンしています。
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/AddSlides.pptx"; | |
const String outPath = u"../out/CloneAtEndOfAnotherPresentation.pptx"; | |
// Instantiate Presentation class | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
//Instantiate target presentation object | |
SharedPtr<Presentation> destPres = MakeObject<Presentation>(); | |
// Accessing Slide by ID from collection | |
SharedPtr<ISlideCollection> slideCollection = destPres->get_Slides(); | |
// Clone the desired slide at end of other presentation | |
slideCollection->AddClone(pres->get_Slides()->idx_get(0)); | |
// Writing the presentation file | |
destPres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
別のプレゼンテーションの特定の位置にスライドをクローン
マスタースライドを持つスライドを1つのプレゼンテーションからクローンし、他のプレゼンテーションで使用する必要がある場合、最初にソースプレゼンテーションから目的のマスタースライドを目的のプレゼンテーションにクローンする必要があります。その後、マスタースライドとともにスライドをクローンするためにそのマスタースライドを使用する必要があります。AddClone(ISlide, IMasterSlide)は、ソースプレゼンテーションではなく目的のプレゼンテーションからマスタースライドを期待します。マスタースライドを持つスライドをクローンするには、以下の手順に従ってください。
- スライドをクローンするソースプレゼンテーションを含むPresentationクラスのインスタンスを作成します。
- スライドをクローンする目的のプレゼンテーションを含むPresentationクラスのインスタンスを作成します。
- クローン対象のスライドとマスタースライドにアクセスします。
- 目的のプレゼンテーションのPresentationオブジェクトによって公開されたマスターコレクションを参照して、IMasterSlideCollectionクラスをインスタンス化します。
- IMasterSlideCollectionオブジェクトによって公開されたAddCloneメソッドを呼び出し、ソースPPTXからクローンするマスターをAddCloneメソッドのパラメータとして渡します。
- 目的のプレゼンテーションのPresentationオブジェクトによって公開されたスライドコレクションを参照して、ISlideCollectionクラスをインスタンス化します。
- ISlideCollectionオブジェクトによって公開されたAddCloneメソッドを呼び出し、クローン対象のソースプレゼンテーションのスライドとマスタースライドをAddCloneメソッドのパラメータとして渡します。
- 修正された目的のプレゼンテーションファイルを保存します。
以下の例では、ソースプレゼンテーションのゼロインデックスにあるマスタースライドを持つスライドを、ソーススライドのマスタースライドを使用して目的のプレゼンテーションの最後にクローンしています。
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/AddSlides.pptx"; | |
const String outPath = u"../out/CloneToAnotherPresentationWithMaster.pptx"; | |
// Instantiate Presentation class | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
//Instantiate target presentation object | |
SharedPtr<Presentation> destPres = MakeObject<Presentation>(); | |
// Accessing Slide by ID from collection | |
SharedPtr<ISlideCollection> slideCollection = destPres->get_Slides(); | |
// Instantiate ISlide from the collection of slides in source presentation along with | |
// Master slide | |
SharedPtr<ISlide> SourceSlide = pres->get_Slides()->idx_get(0); | |
SharedPtr<IMasterSlide> SourceMaster = SourceSlide->get_LayoutSlide()->get_MasterSlide(); | |
// Clone the desired master slide from the source presentation to the collection of masters in the | |
// Destination presentation | |
SharedPtr<IMasterSlideCollection> masters = destPres->get_Masters(); | |
SharedPtr<IMasterSlide> DestMaster = SourceSlide->get_LayoutSlide()->get_MasterSlide(); | |
// Clone the desired master slide from the source presentation to the collection of masters in the | |
// Destination presentation | |
SharedPtr<IMasterSlide> iSlide = masters->AddClone(SourceMaster); | |
// Clone the desired slide from the source presentation with the desired master to the end of the | |
// Collection of slides in the destination presentation | |
slideCollection->AddClone(SourceSlide, iSlide, true); | |
// Clone the desired slide at end of other presentation | |
slideCollection->InsertClone(1, pres->get_Slides()->idx_get(0)); | |
// Writing the presentation file | |
destPres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
指定されたセクションにスライドをクローン
スライドをクローンし、その後同じプレゼンテーションファイル内の異なるセクションで使用したい場合は、AddClone()メソッドを、ISlideCollectionインターフェースによって公開されたものを使用します。Aspose.Slides for C++を使用すると、最初のセクションからスライドをクローンし、その後そのクローンされたスライドを同じプレゼンテーションの第二のセクションに挿入することが可能です。
以下のコードスニペットでは、スライドをクローンし、クローンされたスライドを指定されたセクションに挿入する方法を示しています。
const String outPath = u"../out/CloneSlideIntoSpecifiedSection.pptx"; | |
auto presentation = MakeObject<Presentation>(); | |
presentation->get_Slides()->idx_get(0)->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 200.0f, 50.0f, 300.0f, 100.0f); | |
presentation->get_Sections()->AddSection(u"Section 1", presentation->get_Slides()->idx_get(0)); | |
auto section2 = presentation->get_Sections()->AppendEmptySection(u"Section 2"); | |
presentation->get_Slides()->AddClone(presentation->get_Slides()->idx_get(0), section2); | |
presentation->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |