在Java編程中,如何創建一個空的PPT文檔?
注意:需要訪問網址:http://poi.apache.org/download.html , 下載一個Apache POI軟體包。這裏下載最新版本:poi-bin-3.17-20170915.tar.gz解壓並全部導入 。
需要導入全部包,如下圖所示 -
以下是使用Java創建空PPT文檔的程式。
package com.zaixian;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
public class CreatingBlankPPT {
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("blank_ppt.pptx");
FileOutputStream out = new FileOutputStream(file);
// saving the changes to a file
ppt.write(out);
System.out.println("Presentation created successfully");
out.close();
}
}
執行上面示例代碼,得到以下結果 -
Presentation created successfully
這就創建一個空的PPT檔了。
上一篇:
Java POI PPT
下一篇:
Java POI Excel