Tutorials Navigation
Apache POI PPT Tutorial - Presentation
Tutorial Name: Apache POI PPT Tutorial - Presentation
Category: PC Tutorials
Submitted By: hoot
Date Added:
Comments: 0
Views: 414
Related Forum: PC Building Forum
Share:
Generally, we use MS-PowerPoint to create presentations. Now let us see how to create presentations using Java. 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
To create an empty presentation, you have to instantiate the XMLSlideShow class of the org.poi.xslf.usermodel package
Save the changes to a PPT document using the FileOutputStream class
Given below is the complete program to create a blank MS-PowerPoint presentation.
Save the above Java code as CreatePresentation.java, and then compile and execute it from the command prompt as follows
If your system environment is configured with the POI library, it will compile and execute to generate a blank PPT file named example1.pptx in your current directory and display the following output on the command prompt
The blank PowerPoint document appears as follows
[ Register or Signin to view external links. ]
Editing an Existing Presentation
To open an existing presentation, instantiate the XMLSlideShow class and pass the FileInputStream object of the file to be edited, as an argument to the XMLSlideShow constructor.
You can add slides to a presentation using the createSlide() method of the XMLSlideShow class which is in the org.poi.xslf.usermodel package.
Given below is the complete program to open and add slides to an existing PPT
Save the above Java code as EditPresentation.java, and then compile and execute it from the command prompt as follows
It will compile and execute to generate the following output
The output PPT document with newly added slides looks as follows
[ Register or Signin to view external links. ]
After adding slides to a PPT, you can add, perform, read, and write operations on the slides.
Creating Empty Presentation
To create an empty presentation, you have to instantiate the XMLSlideShow class of the org.poi.xslf.usermodel package
XMLSlideShow ppt = new XMLSlideShow();
Save the changes to a PPT document using the FileOutputStream class
File file = new File("C://POIPPT//Examples//example1.pptx");
FileOutputStream out = new FileOutputStream(file);
ppt.write(out);
Given below is the complete program to create a blank MS-PowerPoint presentation.
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
public class CreatePresentation {
public static void main(String args[]) throws IOException {
//creating a new empty slide show
XMLSlideShow ppt = new XMLSlideShow();
//creating an FileOutputStream object
File file = new File("example1.pptx");
FileOutputStream out = new FileOutputStream(file);
//saving the changes to a file
ppt.write(out);
System.out.println("Presentation created successfully");
out.close()
}
}
Save the above Java code as CreatePresentation.java, and then compile and execute it from the command prompt as follows
$javac CreatePresentation.java
$java CreatePresentation
If your system environment is configured with the POI library, it will compile and execute to generate a blank PPT file named example1.pptx in your current directory and display the following output on the command prompt
Presentation created successfully
The blank PowerPoint document appears as follows
[ Register or Signin to view external links. ]
Editing an Existing Presentation
To open an existing presentation, instantiate the XMLSlideShow class and pass the FileInputStream object of the file to be edited, as an argument to the XMLSlideShow constructor.
File file = new File("C://POIPPT//Examples//example1.pptx");
FileInputstream inputstream = new FileInputStream(file);
XMLSlideShow ppt = new XMLSlideShow(inputstream);
You can add slides to a presentation using the createSlide() method of the XMLSlideShow class which is in the org.poi.xslf.usermodel package.
XSLFSlide slide1 = ppt.createSlide();
Given below is the complete program to open and add slides to an existing PPT
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
public class EditPresentation {
public static void main(String ar[]) throws IOException {
//opening an existing slide show
File file = new File("example1.pptx");
FileInputStream inputstream = new FileInputStream(file);
XMLSlideShow ppt = new XMLSlideShow(inputstream);
//adding slides to the slodeshow
XSLFSlide slide1 = ppt.createSlide();
XSLFSlide slide2 = ppt.createSlide();
//saving the changes
FileOutputStream out = new FileOutputStream(file);
ppt.write(out);
System.out.println("Presentation edited successfully");
out.close();
}
}
Save the above Java code as EditPresentation.java, and then compile and execute it from the command prompt as follows
$javac EditPresentation.java
$java EditPresentation
It will compile and execute to generate the following output
slides successfully added
The output PPT document with newly added slides looks as follows
[ Register or Signin to view external links. ]
After adding slides to a PPT, you can add, perform, read, and write operations on the slides.
Ratings
Comments
Related Tutorials
- 01. Emulating Xbox 360 on PC for Running COD4 With Mods(3,492)
- 02. How to: Matrix Numbers | Batch File(1,903)
- 03. How to Password Protect Files on Windows(857)
- 04. How to play Socom 2/3/ and Combined Assault on PC(6,716)
- 05. Modern Warfare 2 Vac Ban Bypass Tutorial(6,133)
- 06. How to embed an image on TheTechGame(3,098)
- 07. [PC] NIOH 2 OTHER USER SAVE RESIGN(12,981)
- 08. Host bot lobbies! Full Tutorial!(11,241)
- 09. Unban yourself [Plutonium BO2](14,240)
- 10. Fall Guys - How to Change Your Name Color on Fall Guys(8,385)
- 11. Best Crosshair Settings for Valorant(6,525)
- 12. Othercide The Surgeon Boss Guide(2,539)
- 13. Othercide Remembrances Unlock Guide(4,460)
- 14. Othercide Beginners Tips and Tricks(2,708)
- 15. How to Fix Grounded Crashes, Loading Time, Low FPS and Other(4,845)
"Apache POI PPT Tutorial - Presentation" :: Login/Create an Account :: 0 comments