AddingImageToPPT.java错误

时间:2018-08-07 05:20:25

标签: java jar apache-poi javahelp

这两个语句中的错误。

///将图像添加到演示文稿中
int idx =(int)ppt.addPicture(picture,XSLFPictureData.PictureType PNG);

///创建带有给定图片的幻灯片

XSLFPictureShape pic = slide.createPicture(idx);

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFPictureData;
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;

public class Exe2 {
      public static void main(String args[]) throws IOException {

  //creating a presentation
  XMLSlideShow ppt = new XMLSlideShow();


  //creating a slide in it
  XSLFSlide slide = ppt.createSlide();

  //reading an image
  File image = new File("E:/pix/xxx/aaa.jpg");

  //converting it into a byte array
  byte[] picture = IOUtils.toByteArray(new FileInputStream(image));

  //adding the image to the presentation
  int idx =(int) ppt.addPicture(picture, XSLFPictureData.PictureType PNG );

  //creating a slide with given picture on it
  XSLFPictureShape pic = slide.createPicture(idx);

  //creating a file object
  File file = new File("C:/AddingimageToPPT.pptx");
  FileOutputStream out = new FileOutputStream(file);

  //saving the changes to a file
  ppt.write(out);

  System.out.println("image added successfully");
  out.close();

} } ERROR.PNG

rESOURCE: https://www.tutorialspoint.com/javaexamples/add_image_to_slide_ppt.htm

0 个答案:

没有答案