该文将介绍如何使用Spire.Presentation for Java设置幻灯片版式。Spire.Presentation完全支持Microsoft PowerPoint支持的11种版式。
为一个PowerPoint文档设置单一版式
import com.spire.presentation.*;
public class setSlideLayout {
public static void main(String[] args) throws Exception{
//实例化一个Presentation
Presentation ppt = new Presentation();
//删除默认的第一张幻灯片
ppt.getSlides().removeAt(0);
//添加幻灯片并设置版式
ISlide slide = ppt.getSlides().append(SlideLayoutType.TITLE);
//添加内容
IAutoShape shape = (IAutoShape)slide.getShapes().get(0);
shape.getTextFrame().setText("Spire.Presentation");
shape = (IAutoShape)slide.getShapes().get(1);
shape.getTextFrame().setText("Set the Layout of Slide as Title");
//保存文档
ppt.saveToFile("SlideLayout.pptx", FileFormat.PPTX_2013);
ppt.dispose();
}
}
在一个PowerPoint文档中设置多种不同版式
import com.spire.presentation.*;
public class setDifferentSlideLayout {
public static void main(String[] args) throws Exception{
//创建一个Presentation实例
Presentation presentation = new Presentation();
//删除默认的第一张幻灯片
presentation.getSlides().removeAt(0);
//遍历所有版式
for (SlideLayoutType type : SlideLayoutType.values())
{
//按版式新建幻灯片
presentation.getSlides().append(type);
}
//保存文档
presentation.saveToFile("Result.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}
效果图: