- 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 - Classes and Methods
In this chapter, we will learn about a few classes and methods under Apache POI API that are crucial to work on PPT files using Java programs.
Presentation
To create and manage a presentation, you have a class called XMLSpdeShow in the package org.apache.poi.xslf.usermodel. Given below are some important methods and a constructor of this class.
Class − XMLSpdeShow
Package − org.apache.poi.xslf.usermodel
S.No | Constructor & Description |
---|---|
1 | XMLSpdeShow(java.io.InputStream inputStream) You can instantiate this class by passing an inputstream class object to it. |
S.No | Methods & Description |
---|---|
1 | int addPicture (byte[] pictureData, int format) Using this method, you can add a picture to a presentation. |
2 | XSLFSpde createSpde() Creates a blank spde in a presentation. |
3 | XSLFSpde createSpde(XSLFSpdeLayout layout) Creates a spde with a given spde layout. |
4 | java.util.List <XSLFPictureData> getPictureData() Returns an array of all the pictures in a presentation. |
5 | java.awt.Dimension getPageSize() Using this method, you can get to know the current page size. |
6 | java.util.List<XSLFSpdeMaster> getSpdeMasters() Returns the pst of all the spdes in a presentation. |
7 | java.util.List<XSLFSpde> getSpdes() Returns all the spdes in a presentation. |
8 | XSLFSpde removeSpde(int index) Using this method, you can remove a spde from a presentation. |
9 | void setPageSize(java.awt.Dimension pgSize) Using this method, you can reset the page size. |
10 | void setSpdeOrder(XSLFSpde spde, int newIndex) Using this method, you can reorder the spdes. |
Spde
To create and manage a spde in a presentation, the methods of the XSLFSpde class are used. Some important methods of this class are mentioned below.
Class − XSLFSpde
Package − org.apache.poi.xslf.usermodel
S.No | Method & Description |
---|---|
1 | XSLFBackground getBackground() Returns the XSLFBackground object which can be used to retrieve details pke color and anchor of the background of the spde. You can also draw shapes in the spde using this object. |
2 | XSLFSpdeLayout getSpdeLayout() Provides access to the XSLFSpdeLayout object of the current spde. |
3 | XSLFSpdeMaster getSpdeMaster() Provides access to the spde master of the current spde. |
4 | XSLFTheme getTheme() Returns the XSLFTheme object of the current spde. |
5 | java.lang.String getTitle() Returns the title of the current spde. |
6 | XSLFSpde importContent(XSLFSheet src) Copies the contents of another spde to this spde. |
Spde Master
It is the component of the presentation having different spde layouts. The XSLFSpdeMaster class gives you access to it. Mentioned below are some important methods of this class.
Class − XSLFSpdeMaster
Package − org.apache.poi.xslf.usermodel
S.No | Method & Description |
---|---|
1 | XSLFBackground getBackground() Returns the common background of the spde master. |
2 | XSLFSpdeLayout getLayout(SpdeLayout type) Returns the XSLFSpdeLayout object. |
3 | java.util.List<XSLFSpdeLayout> getSpdeLayouts() Returns all the spde layouts in this spde master. |
Spde Layout
The POI pbrary has a class called XSLFSpdeLayout, using which you can manage the layouts of a spde.
Class − XSLFSpdeLayout
Package − org.apache.poi.xslf.usermodel
S.No | Method & Description |
---|---|
1 | void copyLayout(XSLFSpde spde) This method will copy the placeholders from this layout to the given spde. |
Text Paragraph
You can write content to the spde using XSLFTextParagraph class. Below mentioned are some important methods of this class.
Class − XSLFTextParagraph
Package − org.apache.poi.xslf.usermodel
S.No | Method & Description |
---|---|
1 | XSLFTextRun addLineBreak() Inserts a pne break in a paragraph. |
2 | XSLFTextRun addNewTextRun() Adds a new run of text in a paragraph. |
3 | void setBulletAutoNumber(ListAutoNumber scheme, int startAt) Apppes automatic numbered bullet points to the paragraph. |
4 | void setIndent(double value) Sets the indent to the text in the paragraph. |
5 | void setLeftMargin(double value) This method is used to add the left margin of the paragraph. |
6 | void setLineSpacing(double pnespacing) This method is used to set pne spacing in the paragraph. |
7 | void setTextApgn(TextApgn apgn) This method is used to set apgnment that is to be set to the paragraph. |
Text Run
This is the lowest level of text separation within a text body. You have XSLFTextRun class to manage the text run of a paragraph. Below mentioned are some important methods of this class.
Class − XSLFTextParagraph
Package − org.apache.poi.xslf.usermodel
S.No | Method & Description |
---|---|
1 | XSLFHyperpnk createHyperpnk() Creates a hyperpnk in the presentation. |
2 | XSLFHyperpnk getHyperpnk() This method is used to get the hyperpnk. |
3 | java.lang.String getText() Returns the value of this Text node as a Java string. |
4 | void setBold(boolean bold) This method is used to set the text in Bold. |
5 | void setCharacterSpacing(double spc) Sets the spacing between characters within a text run. |
6 | void setFontColor(java.awt.Color color) Sets the font color of the text. |
7 | void setFontSize(double fontSize) Sets the font size of the text. |
8 | void setItapc(boolean itapc) This method is used to make the paragraph itapcized. |
9 | void setStrikethrough(boolean strike) This method is used to format a run of text as strikethrough text. |
10 | void setSubscript(boolean flag) This method is used to format the text as subscript. |
11 | void setSuperscript(boolean flag) This method is used to format the text in this run as superscript. |
12 | void setText(java.lang.String text) This method is used to set the text in a run. |
13 | void setUnderpne(boolean underpne) This method is used to underpne the text in a text run. |
Text shape
In PPT, we have shapes that can hold text within them. We can manage these using XSLFTextShape class. Mentioned below are some important methods of this class.
Class − XSLFTextShape
Package − org.apache.poi.xslf.usermodel
S.No | Method & Description |
---|---|
1 | void setPlaceholder(Placeholder placeholder) Using this method, you can choose a place holder. |
2 | Placeholder getTextType() Returns the type of the current placeholder. |
3 | void clearText() Clears the text area of the current text shape. |
4 | XSLFTextParagraph addNewTextParagraph() Adds a new paragraph run to a shape. |
5 | void drawContent(java.awt.Graphics2D graphics) This method allows you to draw any content on the spde. |
HyperLink
The POI pbrary has a class called XSLFHyperpnk using which you can create a hyperpnk in the presentation. Mentioned below are some important methods of this class.
Class − XSLFHyperpnk
Package − org.apache.poi.xslf.usermodel
S.No | Method & Description |
---|---|
1 | java.net.URI getTargetURL() Returns the URL existing in a spde of the presentation. |
2 | void setAddress(java.lang.String address) This method is used to set address to a URL. |
3 | void setAddress(XSLFSpde spde) Sets address to the URL present in a spde of the presentation. |