- 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
以下快照显示第一个演示文稿 -
以下快照显示第二个演示文稿 -
下面是合并两个幻灯片后的程序输出。此处可以看到之前幻灯片的内容已合并在一起。
广告