Apache POI PPT Presentation Apache POI PPT

How to create an empty presentation using Apache POI PPT?

MS-PowerPoint is basically used for creating presentations. In this chapter we will explain how to create presentations using Java and after completion of this chapter, you will be able to create new MS-PowerPoint presentations and open existing PPTs with your Java program.

Creating Empty Presentation

For creating an empty presentation, first instantiate the XMLSlideShow class of the org.poi.xslf.usermodel package:

Save the changes to a PPT document using the FileOutputStream class:

Below is the complete program for creating a blank MS-PowerPoint presentation.

Save the above Java code as CreatePresentation.java and then compile and execute it from the command prompt as shown below:

If your system environment is configured with POI library, then it will compile and execute for generating a blank PPT file named example1.pptx in your current directory and it will display below output on the command prompt:

A blank PowerPoint document will appear as shown below:


Editing an Existing Presentation

For opening an existing presentation, instantiate XMLSlideShow class and pass the FileInputStream object of the file to be edited, as an argument to the XMLSlideShow constructor.

Slides can be added to a presentation using createSlide() method of the XMLSlideShow class which is in the org.poi.xslf.usermodel package.

Below is the complete program for opening and adding slides to an existing PPT:

Save the above Java code as EditPresentation.java and then compile and execute it from the command prompt as shown below:

It will compile and execute to generate below output:

Output PPT document with newly added slides will look like as shown below:


After adding slides to a PPT, you can add, perform, read, and write operations on the slides.

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apache POI PPT Topics