幻灯片母版,可在幻灯片中预先存储设计模板信息,包括字形、占位符大小或位置、背景设计和配色方案等;对设定好的母版可应用于所有幻灯片,也可设计多个不同母版应用于不同幻灯片。下面通过Java代码示例介绍如何创建单一母版以及不同母版。
使用工具:Free Spire.Office for Java(免费版)
Jar获取及导入:官网下载jar包,并解压将lib文件夹下的jar文件导入Java程序,或者通过maven仓库下载导入。
1. 创建单一母版,应用到所有幻灯片
import com.spire.presentation.*; import com.spire.presentation.drawing.BackgroundType; import com.spire.presentation.drawing.FillFormatType; import com.spire.presentation.drawing.IImageData; import com.spire.presentation.drawing.PictureFillType; import javax.imageio.ImageIO; import java.awt.*; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.FileInputStream; public class CreateMasterSlide { public static void main(String[] args) throws Exception { //创建PPT文档,并设置幻灯片大小 Presentation ppt = new Presentation(); ppt.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9); //获取第一张母版 IMasterSlide masterSlide = ppt.getMasters().get(0); //设置母版背景 BufferedImage image = ImageIO.read(new FileInputStream("tp.png")); IImageData imageData = ppt.getImages().append(image); masterSlide.getSlideBackground().setType(BackgroundType.CUSTOM); masterSlide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE); masterSlide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH); masterSlide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData); //添加图片到母版 image = ImageIO.read(new FileInputStream("logo.png")); imageData = ppt.getImages().append(image); IEmbedImage imageShape = masterSlide.getShapes().appendEmbedImage(ShapeType.RECTANGLE,imageData,new Rectangle2D.Float((float) ppt.getSlideSize().getSize().getWidth()-240,40,60,60)); imageShape.getLine().setFillType(FillFormatType.NONE); //添加文字到母版 IAutoShape textShape = masterSlide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float((float) ppt.getSlideSize().getSize().getWidth()-230,85,200,30)); textShape.getTextFrame().setText("文娱传媒"); textShape.getTextFrame().getTextRange().setFontHeight(20f); textShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID); textShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.black); textShape.getTextFrame().getTextRange().getParagraph().setAlignment(TextAlignmentType.CENTER); textShape.getFill().setFillType(FillFormatType.NONE); textShape.getLine().setFillType(FillFormatType.NONE); //添加一张幻灯片(创建PPT文档时,已默认生成一张幻灯片,这里添加一张幻灯片可对比查看母版添加效果) ppt.getSlides().append(); //保存文档 ppt.saveToFile("CreateSlideMaster.pptx", FileFormat.PPTX_2013); ppt.dispose(); } }
2. 创建多个母版,应用于不同幻灯片
import com.spire.presentation.*; import com.spire.presentation.drawing.BackgroundType; import com.spire.presentation.drawing.FillFormatType; import com.spire.presentation.drawing.IImageData; import com.spire.presentation.drawing.PictureFillType; import javax.imageio.ImageIO; import java.awt.*; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.FileInputStream; public class CreateMasterSlide2 { public static void main(String[] args) throws Exception{ //创建PPT文档,并设置幻灯片大小 Presentation ppt = new Presentation(); ppt.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9); //插入4页幻灯片(连同默认的幻灯片,文档中共5页) for (int i = 0; i < 4; i++) { ppt.getSlides().append(); } //获取默认的母版 IMasterSlide first_master = ppt.getMasters().get(0); //创建并获取第二个母板 ppt.getMasters().appendSlide(first_master); IMasterSlide second_master = ppt.getMasters().get(1); //为两个母版分别设置不同的背景图片 BufferedImage image = ImageIO.read(new FileInputStream("pic1.png")); IImageData imageData = ppt.getImages().append(image); first_master.getSlideBackground().setType(BackgroundType.CUSTOM); first_master.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE); first_master.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH); first_master.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData); IAutoShape textShape = first_master.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float((float) ppt.getSlideSize().getSize().getWidth()/3,180,200,30)); textShape.getTextFrame().setText("首页母版"); textShape.getTextFrame().getTextRange().setFontHeight(40f); textShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID); textShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.red); textShape.getTextFrame().getTextRange().getParagraph().setAlignment(TextAlignmentType.CENTER); textShape.getFill().setFillType(FillFormatType.NONE); textShape.getLine().setFillType(FillFormatType.NONE); image = ImageIO.read(new FileInputStream("pic2.png")); imageData = ppt.getImages().append(image); second_master.getSlideBackground().setType(BackgroundType.CUSTOM); second_master.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE); second_master.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH); second_master.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData); //在第一页应用第一个母版及版式(板式6为空板式) ppt.getSlides().get(0).setLayout(first_master.getLayouts().get(6)); //在剩下的幻灯片应用第二个母版及版式 for (int i = 1; i < ppt.getSlides().getCount(); i++) { ppt.getSlides().get(i).setLayout(second_master.getLayouts().get(6)); } //保存文档 ppt.saveToFile("MultiSlideMaters.pptx", FileFormat.PPTX_2013); ppt.dispose(); } }
相关推荐
幻灯片母版可供用户设置幻灯片的样式,本文将介绍如何用Java创建并应用单个或多个幻灯片母版。感兴趣可以了解一下
该资源包含了38个优美的幻灯片母板,以及很多好看的背景,这些PPT模板你可以为你presentation增色不少。
一劳永逸:对幻灯片母版的更改,将应用于所有幻灯片页面,PPT页数越多版式越复杂,用母版越高效;母版中设置的版式,普通视图中其他人无法意外删除或编辑;版式里可以一键换母版。母版类型:讲义母版;备注母版;...
除了自动套用Office PowerPoint 2016提供的模板,用户也可以创建模板,方法是:创建一个或多个母版,添加版式,然后应用主题。 (1)设计背景 设计幻灯片模板中的“标题”背景,标题与内容背景,其中“标题与内容”...
Java poi ppt ①创建新的PPT文档 ②设置母版 ③创建幻灯片并插入文本 ④插入图片,支持多种格式 ⑤插入表格 ......
计算机应用 幻灯片母版设计.docx 学习资料 复习资料 教学资源
设置幻灯片母版课件PPT学习教案.pptx
java实现poi模板生成PPT文件代码:两个迭代版本。java实现poi模板生成PPT文件代码:两个迭代版本。
PowerPoint2021设置幻灯片母版版式及背景图片.docx
浅绿色护眼幻灯片母版 带小朋友图案
自学视频教程
幻灯母板幻灯母板幻灯母板幻灯母板幻灯母板
第06章、幻灯片母版、主题和模板
PowerPoint2021中怎样查看幻灯片母版.docx
首先说明两点: 一、360会报毒,我使用起来觉得很好,所以放在这里,以备...PPT文件批量设置图片:批量为幻灯片母版插入图片或批量设置背景图片。 幻灯片文件批量合并:将多个幻灯片文档(PPT文档)合并成一个PPT文档。
PowerPoint2021中怎样查看幻灯片母版?.docx
办公自动化WPS 2019 演示基础课程幻灯片母版原理.mp4
要求:选取适当的设计模板,通过幻灯片母版为每张幻灯片加上编号和适当的个人标 志。在演示幻灯片时,对标题幻灯片和其他幻灯片分别加上不同的动画效果。 一、简答(每小题10分,共50分。) 1.什么叫位?什么叫...
初中信息技术的幻灯片教学第1课,教学目标是掌握幻灯片2010中母板的使用,
PPT如何应用母版图文教学