本文概述
- Apache POI标题幻灯片示例
- Apache POI幻灯片内容示例
Apache POI标题幻灯片示例
package poiexample;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.poi.xslf.usermodel.SlideLayout;
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;
import org.apache.poi.xslf.usermodel.XSLFTextShape;
public class CreatingPptExample {
public static void main(String[] args) {
XMLSlideShow ppt = new XMLSlideShow();
try (OutputStream os = new FileOutputStream("srcmini.pptx")) {
XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
XSLFSlide slide = ppt.createSlide(titleLayout);
XSLFTextShape title = slide.getPlaceholder(0);
title.setText("Enter Title Here");
ppt.write(os);
}catch(Exception e) {
System.out.println(e);
}
}
}
输出:
Following slide has title which was set by the Java program.
文章图片
除标题外,现在下面的示例将内容设置为创建的幻灯片。
Apache POI幻灯片内容示例
package poiexample;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.poi.xslf.usermodel.SlideLayout;
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;
import org.apache.poi.xslf.usermodel.XSLFTextShape;
public class TitleContentExample {
public static void main(String[] args) {
XMLSlideShow ppt = new XMLSlideShow();
try (OutputStream os = new FileOutputStream("srcmini.pptx")) {
XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
XSLFSlideLayout tc = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
XSLFSlide slide = ppt.createSlide(tc);
XSLFTextShape title = slide.getPlaceholder(0);
title.setText("Title here");
XSLFTextShape body = slide.getPlaceholder(1);
body.clearText();
body.addNewTextParagraph().addNewTextRun().setText("This is a new slide created using Java program.");
ppt.write(os);
}catch(Exception e) {
System.out.println(e);
}
}
}
【apache poi powerpoint布局】输出:
文章图片
推荐阅读
- apache poi powerpoint幻灯片重新排序
- apache poi powerpoint图像
- apache poi powerpoint页面大小
- apache poi powerpoint幻灯片
- apache poi word文档段落
- apache poi超链接
- apache poi word表格
- apache poi word风格
- apache poi word对齐