- Apache POI PPT Tutorial
- Apache POI PPT - Home
- Apache POI PPT - Overview
- Apache POI PPT - Java API Flavors
- Apache POI PPT - Installation
- Apache POI PPT - Classes & Methods
- Apache POI PPT - Presentation
- Apache POI PPT - Slide Layouts
- Apache POI PPT - Slide Management
- Apache POI PPT - Images
- Apache POI PPT - Creating Hyperlinks
- Apache POI PPT - Reading Shapes
- Apache POI PPT - Formatting Text
- Apache POI PPT - Merging
- Apache POI PPT - PPT to Image
- Apache POI PPT Resources
- Apache POI PPT - Quick Guide
- Apache POI PPT - Useful Resources
- Apache POI PPT - Discussion
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
以下快照显示了第一个演示文稿 -
以下快照显示了第二个演示 -
下面给出的是合并两张幻灯片后程序的输出。在这里您可以看到先前幻灯片的内容合并在一起。