如何使用java合并两个PPT。(How to merge two PPTs using java.)
优质
小牛编辑
124浏览
2023-12-01
问题描述 (Problem Description)
如何使用java合并两个PPT。
解决方案 (Solution)
以下是使用java合并两个PPT的程序。
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 = "C:/poippt/presentation1.pptx";
String file2 = "C:/poippt/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 = "C:/poippt/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();
}
}