2つの PowerPoint プレゼンテーションを処理するときに、特定のスライドを1つのプレゼンテーションから別のプレゼンテーションの指定された場所にコピーする場合は、プログラミングによってこの機能を実現します。手動でコピーして貼り付けるよりも、Java コードを使用した自動操作の方法がより迅速で効果的です。この記事では、Spire.Presentation for Java を使用して2 つの異なる PowerPoint 文書間でスライドをコピーする方法を示します。 Spire.Presentation for Java をインストールします まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。 <repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.presentation</artifactId> <version>8.5.2</version> </dependency> </dependencies> 2つの PowerPoint 文書間でスライドをコピーする Spire.Presentation for Java が提供する Presentation.getSlides().insert() と Presentation.getSlides().append() メソッドは、それぞれ指定された場所へのスライドの挿入と追加をサポートします。以下に詳細な操作方法を示します。 Presentation オブジェクトを作成する。 Presentation.loadFromFile() メソッドを使用して sample1 を読み込みます。 別の Presentation オブジェクトを作成する。 Presentation.loadFromFile() メソッドを使用して sample2 を読み込みます。 Presentation.getSlides().get() メソッドを使用して sample1 の特定のスライドを取得し、Presentation.getSlides().insert() メソッドを使用して sample2 の指定された位置にそのコピーを挿入します。 Presentation.getSlides().get() メソッドを使用して sample1 の別の特定のスライドを取得し、Presentation.getSlides().append() メソッドを使用して sample2 の最後にそのコピーを追加します。 Presentation.saveToFile() メソッドを使用して、sample2 を別のファイルに保存します。 Java import com.spire.presentation.FileFormat; import com.spire.presentation.Presentation; public class CopySlidesBetweenPPT { public static void main(String[] args) throws Exception { //sample1をロードするためのPresentationオブジェクトを作成する Presentation pptOne= new Presentation(); pptOne.loadFromFile("sample1.pptx"); //sample2をロードするための別のPresentationオブジェクトを作成する Presentation pptTwo = new Presentation(); pptTwo.loadFromFile("sample2.pptx"); //sample1のスライドをsample2の指定された場所に挿入する pptTwo.getSlides().insert(0,pptOne.getSlides().get(0)); //sample1のスライドをsample2の最後に追加する pptTwo.getSlides().append(pptOne.getSlides().get(3)); //sample2を別のファイルに保存する pptTwo.saveToFile("output/CopySlidesBetweenPPT.pptx", FileFormat.PPTX_2013); pptTwo.dispose(); } } 一時ライセンスを申請する 結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。 にお問い合わせ、30 日間有効な一時ライセンスを取得してください。