
- Apache POI PPT 教程
- Apache POI PPT - 主頁
- Apache POI PPT - 概述
- Apache POI PPT - Java API 型別
- Apache POI PPT - 安裝
- Apache POI PPT - 類和方法
- Apache POI PPT - 演示
- Apache POI PPT - 幻燈片佈局
- Apache POI PPT - 幻燈片管理
- Apache POI PPT - 圖片
- Apache POI PPT - 建立超連結
- Apache POI PPT - 讀取形狀
- Apache POI PPT - 設定文字格式
- Apache POI PPT - 合併
- Apache POI PPT - PPT 轉影像
- Apache POI PPT 資源
- Apache POI PPT - 快速指南
- Apache POI PPT - 有用資源
- Apache POI PPT - 討論
Apache POI PPT - 合併
可以使用 **XMLSlideShow** 類的 **importContent()** 方法合併多個簡報。下面是合併兩個簡報的完整程式 -
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
以下快照顯示第一個簡報 -

以下快照顯示第二個簡報 -

下面是合併兩個幻燈片後的程式輸出。此處可以看到之前幻燈片的內容已合併在一起。

廣告