Apache POI PPT Tutorial
Selected Reading
- Apache POI PPT - Discussion
- Apache POI PPT - Useful Resources
- Apache POI PPT - Quick Guide
- Apache POI PPT - PPT to Image
- Apache POI PPT - Merging
- Apache POI PPT - Formatting Text
- Apache POI PPT - Reading Shapes
- Apache POI PPT - Creating Hyperlinks
- Apache POI PPT - Images
- Apache POI PPT - Slide Management
- Apache POI PPT - Slide Layouts
- Apache POI PPT - Presentation
- Apache POI PPT - Classes & Methods
- Apache POI PPT - Installation
- Apache POI PPT - Java API Flavors
- Apache POI PPT - Overview
- Apache POI PPT - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache POI PPT - Reading Shapes
Apache POI PPT - Reading Shapes
You can get a count of the number of shapes used in a presentation using the method getShapeName() of the XSLFShape class. Given below is the program to read the shapes from a presentation −
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; import org.apache.poi.xslf.usermodel.XMLSpdeShow; import org.apache.poi.xslf.usermodel.XSLFShape; import org.apache.poi.xslf.usermodel.XSLFSpde; pubpc class ReadingShapes { pubpc static void main(String args[]) throws IOException { //creating a spdeshow File file = new File("shapes.pptx"); XMLSpdeShow ppt = new XMLSpdeShow(new FileInputStream(file)); //get spdes List<XSLFSpde> spde = ppt.getSpdes(); //getting the shapes in the presentation System.out.println("Shapes in the presentation:"); for (int i = 0; i < spde.size(); i++){ List<XSLFShape> sh = spde.get(i).getShapes(); for (int j = 0; j < sh.size(); j++){ //name of the shape System.out.println(sh.get(j).getShapeName()); } } FileOutputStream out = new FileOutputStream(file); ppt.write(out); out.close(); } }
Save the above Java code as ReadingShapes.java, and then compile and execute it from the command prompt as follows −
$javac ReadingShapes.java $java ReadingShapes
It will compile and execute to generate the following output.
Shapes in the presentation: Rectangle 1 Oval 1 Isosceles Triangle 1
The newly added spde with the various shapes appears as follows −
Advertisements