欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JAVA POI ppt操作

程序员文章站 2022-07-13 12:29:48
...
package package1;

import java.io.File;
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 CreatePresentation {
	   
	   public static void main(String args[]) throws IOException{
	   
	      //creating a new empty slide show
	      XMLSlideShow ppt = new XMLSlideShow();	     
	      
	      //creating an FileOutputStream object
	      File file =new File("example2.pptx");
	      FileOutputStream out = new FileOutputStream(file);
	      
	      //saving the changes to a file
	      //ppt.write(out);
	      System.out.println("Presentation created successfully");
	      out.close();
	      ppt.close();
	   }
	}
package ppt;

import java.io.File;
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;

import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;

public class CreatePresentation {
	   
	   public static void main(String args[]) throws IOException{
	   
	      //creating a new empty slide show
	      XMLSlideShow ppt = new XMLSlideShow();	     
	      
	      //creating an FileOutputStream object
	      File file =new File("example2.pptx");
	      FileOutputStream out = new FileOutputStream(file);
	      
	      
	      //getting the list of all slide masters
	      for(XSLFSlideMaster master : ppt.getSlideMasters()){
	   
	         //getting the list of the layouts in each slide master
	         for(XSLFSlideLayout layout : master.getSlideLayouts()){
	   
	            //getting the list of available slides
	            System.out.println(layout.getType());
	         } 
	      }
	      
	      //saving the changes to a file
	      ppt.write(out);
	      System.out.println("Presentation created successfully");
	      out.close();
	      ppt.close();
	   }
	}