如何使用 Java 合并两个 PPT



问题描述

如何使用 Java 合并两个 PPT。

解决方案

以下是使用 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();
   }
} 

输入

Merge PPT

 

Merge Input

输出

Merge Output
java_apache_poi_ppt
广告
© . All rights reserved.