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