PowerPoint主要用于演示文稿的制做,在演讲、教学、产品演示等方面获得了普遍的应用。为了提升PPT的制做效率,掌握操做幻灯片的方法极为重要。所以,本文将经过使用Java程序来介绍如何添加、隐藏、删除PPT文档中的幻灯片及调整幻灯片顺序。html
方法1:经过官网下载获取jar包。解压后将lib文件夹下的Spire.Presentation.jar文件导入Java程序。(以下图)java
方法2:经过maven仓库安装导入。具体安装教程详见此网页。app
import com.spire.presentation.*; public class AddSlide { public static void main(String[] args) throws Exception { //建立一个PowerPoint文档并加载示例文档 Presentation presentation = new Presentation(); presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx"); //在文档末尾添加新幻灯 presentation.getSlides().append(); //在第三页插入空白幻灯片 presentation.getSlides().insert(2); //保存文档 presentation.saveToFile("output/AddSlide.pptx", FileFormat.PPTX_2010); } }
新幻灯片添加效果:maven
import com.spire.presentation.*; public class HideSlide { public static void main(String[] args) throws Exception { //建立一个PowerPoint文档并加载示例文档 Presentation presentation = new Presentation(); presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx"); //隐藏第二张幻灯片 presentation.getSlides().get(1).setHidden(true); //保存文档 presentation.saveToFile("output/Hideslide.pptx", FileFormat.PPTX_2010); } }
幻灯片隐藏效果:ide
import com.spire.presentation.*; public class RemoveSlide { public static void main(String[] args) throws Exception { //建立一个PowerPoint文档并加载示例文档 Presentation presentation = new Presentation(); presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx"); //删除第二张幻灯片 presentation.getSlides().removeAt(1); //保存文档 presentation.saveToFile("output/Removeslide.pptx", FileFormat.PPTX_2010); } }
幻灯片删除效果:工具
import com.spire.presentation.*; public class ReorderSlide { public static void main(String[] args) throws Exception { //建立一个PowerPoint文档并加载示例文档 Presentation presentation = new Presentation(); presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx"); //获取文档中的第一张幻灯片并将其设置为第二张 ISlide slide = presentation.getSlides().get(0); slide.setSlideNumber(2); //保存文档 presentation.saveToFile("output/Reorderslide.pptx", FileFormat.PPTX_2010); } }
幻灯片顺序调整结果:spa
(本文完)3d