Apache-poi-ppt-merging

提供:Dev Guides
移動先:案内検索

Apache POI PPT-マージ

*XMLSlideShow* クラスの* importContent()*メソッドを使用して、複数のプレゼンテーションをマージできます。 以下は、2つのプレゼンテーションをマージするための完全なプログラムです-
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;

public class MergingMultiplePresentations {

      public static void main(String args[]) throws IOException {

     //creating empty presentation
      XMLSlideShow ppt = new XMLSlideShow();

     //taking the two presentations that are to be merged
      String file1 = "presentation1.pptx";
      String file2 = "presentation2.pptx";
      String[] inputs = {file1, file2};

      for(String arg : inputs){

         FileInputStream inputstream = new FileInputStream(arg);
         XMLSlideShow src = new XMLSlideShow(inputstream);

         for(XSLFSlide srcSlide : src.getSlides()) {

           //merging the contents
            ppt.createSlide().importContent(srcSlide);
         }
      }

      String file3 = "combinedpresentation.pptx";

     //creating the file object
      FileOutputStream out = new FileOutputStream(file3);

     //saving the changes to a file
      ppt.write(out);
      System.out.println("Merging done successfully");
      out.close();
   }
}

上記のコードを MergingMultiplePresentations.java として保存し、次のようにコマンドプロンプトからコンパイルして実行します-

$javac MergingMultiplePresentations.java
$java MergingMultiplePresentations

次の出力を生成するためにコンパイルおよび実行されます-

Merging done successfully

次のスナップショットは、最初のプレゼンテーションを示しています-

Presentation1

次のスナップショットは、2番目のプレゼンテーションを示しています-

Presentation2

以下は、2つのスライドを結合した後のプログラムの出力です。 ここでは、以前のスライドのコンテンツがマージされたことがわかります。

複合プレゼンテーション