PowerPoint – это эффективный инструмент для людей, позволяющий отображать информацию и делать презентации. В этой статье будет продемонстрировано, как программно управлять слайдами презентации с помощью бесплатного Spire. Презентация для Java. Следующие примеры включают добавление нового слайда в документ PowerPoint, удаление существующего слайда, скрытие слайда из документа PowerPoint и изменение порядка слайдов в презентации.
Зависимость от импорта jar (2 Метода) ● Загрузите Бесплатный шпиль. Презентация для Java и распакуйте ее. Затем добавьте Шпиль.Презентация.файл jar в ваш проект в качестве зависимости.
● Вы также можете добавить зависимость jar в свой проект maven, добавив следующие конфигурации в pom.xml .
com.e-iceblue e-iceblue http://repo.e-iceblue.com/nexus/content/groups/public/ e-iceblue spire.presentation.free 3.9.0
Добавьте 2 новых слайда в существующий документ PowerPoint:
import com.spire.presentation.*;
public class AddSlides {
public static void main(String[] args) throws Exception {
//Create a PPT document and load file
Presentation presentation = new Presentation();
presentation.loadFromFile("input1.pptx");
//add new slide at the end of the document
presentation.getSlides().append();
//insert a blank slide before the second slide
presentation.getSlides().insert(1);
//Save the document
presentation.saveToFile("output/AddSlide.pptx", FileFormat.PPTX_2010);
}
}
Скрыть слайд, который мы не хотим показывать аудитории, не удалив его:
import com.spire.presentation.*;
public class HideSlides {
public static void main(String[] args) throws Exception {
//Create a PPT document and load file
Presentation presentation = new Presentation();
presentation.loadFromFile("input1.pptx");
//Hide the second slide
presentation.getSlides().get(1).setHidden(true);
//Save the document
presentation.saveToFile("output/HideSlide.pptx", FileFormat.PPTX_2010);
}
}
Удаление слайда из документа PowerPoint:
import com.spire.presentation.*;
public class DeleteSlides {
public static void main(String[] args) throws Exception {
//Create a PPT document and load file
Presentation presentation = new Presentation();
presentation.loadFromFile("input1.pptx");
//Remove the third slide
presentation.getSlides().removeAt(2);
//Save the document
presentation.saveToFile("output/Removeslide.pptx", FileFormat.PPTX_2010);
}
}
Изменение порядка слайдов в документе PowerPoint:
import com.spire.presentation.*;
public class SlidesOrder {
public static void main(String[] args) throws Exception {
//Create a PPT document and load file
Presentation presentation = new Presentation();
presentation.loadFromFile("input1.pptx");
//Move the first slide to the second slide position
ISlide slide = presentation.getSlides().get(0);
slide.setSlideNumber(2);
//Save the document
presentation.saveToFile("output/Reorderslide.pptx", FileFormat.PPTX_2010);
}
}
Оригинал: “https://dev.to/jazzzzz/operate-the-presentation-slides-using-java-489h”