Apache POI PPT Classes and Methods Apache POI PPT

What are the different classes and methods of Apache POI PPT?

This chapter will give you detailed description on few classes and methods in Apache POI API which are important to work on PPT files using Java programs.

Presentation

For creating and managing a presentation, there is a class called XMLSlideShow in the package org.apache.poi.xslf.usermodel. Below are some of the important methods and a constructor of this class.

Class : XMLSlideShow

Package : org.apache.poi.xslf.usermodel

S.No

Constructor and Description

1

XMLSlideShow(java.io.InputStream inputStream)

You can instantiate this class by passing an inputstream class object to it.

S.No

Methods and Description

1

int addPicture (byte[] pictureData, int format)

This method is used for adding a picture to a presentation.

2

XSLFSlide createSlide()

This will create a blank slide in a presentation.

3

XSLFSlide createSlide(XSLFSlideLayout layout)

This will create a slide with a given slide layout.

4

java.util.List <XSLFPictureData> getAllPictures()

This will return an array of all the pictures in a presentation.

5

java.awt.Dimension getPageSize()

This method is used for knowing the current page size.

6

XSLFSlideMaster[] getSlideMasters()

This will return the array of all the slides in a presentation.

7

XSLFSlide[] getSlides()

This will return all the slides in a presentation.

8

XSLFSlide removeSlide(int index)

This method is used for removing a slide from a presentation.

9

void setPageSize(java.awt.Dimension pgSize)

This method is used to reset the page size.

10

void setSlideOrder(XSLFSlide slide, int newIndex)

This method is used to reorder the slides.

Slide

For creating and managing slides in a presentation, methods of the XSLFSlide class are used. Below are some important methods of this class.

Class : XSLFSlide

Package : org.apache.poi.xslf.usermodel

S.No

Methods and Description

1

XSLFBackground getBackground()

This will return the XSLFBackground object which is used for retrieving details like color and anchor of the background of the slide. You can also draw shapes in the slide using this object.

2

XSLFSlideLayout getSlideLayout()

This will provide access to the XSLFSlideLayout object of the current slide.

3

XSLFSlideMaster getSlideMaster()

This will provide access to the slide master of the current slide.

4

XSLFTheme getTheme()

This will return the XSLFTheme object of the current slide.

5

java.lang.String getTitle()

This will return the title of the current slide.

6

XSLFSlide importContent(XSLFSheet src)

This will copy the contents of another slide to this slide.

Slide Master

It is a component of presentation which has different slide layouts and XSLFSlideMaster class will give you access to it. Below are some important methods of this class.

Class : XSLFSlideMaster

Package : org.apache.poi.xslf.usermodel

S.No

Description

1

XSLFBackground getBackground()

This will return the common background of the slide master.

2

XSLFSlideLayout getLayout(SlideLayout type)

This will return the XSLFSlideLayout object.

3

XSLFSlideLayout[] getSlideLayouts()

This will return all the slide layouts in this slide master.

Slide Layout

POI library has a class called XSLFSlideLayout which is used for managing the layouts of a slide.

Class : XSLFSlideLayout

Package : org.apache.poi.xslf.usermodel

S.No

Method and Description

1

void copyLayout(XSLFSlide slide)

It copies the placeholders from this layout to the given slide.

Text Paragraph

Content can be written to the slide using XSLFTextParagraph class. Below are some important methods of this class.

Class : XSLFTextParagraph

Package : org.apache.poi.xslf.usermodel

S.No

Methods and Description

1

XSLFTextRun addLineBreak()

This will insert a line break in a paragraph.

2

XSLFTextRun addNewTextRun()

This will add a new run of text in a paragraph.

3

void setBulletAutoNumber(ListAutoNumber scheme, int startAt)

This will apply automatic numbered bullet points to the paragraph.

4

void setIndent(double value)

This will set the indent to the text in the paragraph.

5

void setLeftMargin(double value)

This method is used for adding left margin of the paragraph.

6

void setLineSpacing(double linespacing)

This method is used to set line spacing in the paragraph.

7

void setTextAlign(TextAlign align)

This method is used to set alignment that is to be set to the paragraph.

Text Run

This is the lowest level of text separation within a text body and XSLFTextRun class is used for managing the text run of a paragraph. Below are some important methods of this class.

Class : XSLFTextParagraph

Package : org.apache.poi.xslf.usermodel

S.No

Methods and Description

1

XSLFHyperlink createHyperlink()

This will create a hyperlink in the presentation.

2

XSLFHyperlink getHyperlink()

This method is used for getting the hyperlink.

3

java.lang.String getText()

This will return 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)

This will set the spacing between characters within a text run.

6

void setFontColor(java.awt.Color color)

This will set the font color of the text.

7

void setFontSize(double fontSize)

This will set the font size of the text.

8

void setItalic(boolean italic)

This method is used for making the paragraph italicized.

9

void setStrikethrough(boolean strike)

This method is used for formatting a run of text as strikethrough text.

10

void setSubscript(boolean flag)

This method is used for formatting the text as subscript.

11

void setSuperscript(boolean flag)

This method is used for formatting 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 setUnderline(boolean underline)

This method is used for underlining the text in a text run.

Text shape

PPT has shapes which can hold the text within them and these can be managed using XSLFTextShape class. Below are some important methods of this class.

Class : XSLFTextShape

Package : org.apache.poi.xslf.usermodel

S.No

Methods and Description

1

void setPlaceholder(Placeholder placeholder)

This method is used to choose a place holder.

2

Placeholder getTextType()

This will return the type of the current placeholder.

3

void clearText()

This will clear the text area of the current text shape.

4

XSLFTextParagraph addNewTextParagraph()

This will add a new paragraph run to a shape.

5

void drawContent(java.awt.Graphics2D graphics)

This method will help in drawing any content on the slide.

HyperLink

POI library has a class called XSLFHyperlink which is used for creating a hyperlink in the presentation. Below are some important methods of this class.

Class : XSLFHyperlink

Package : org.apache.poi.xslf.usermodel

S.No

Methods and Description

1

java.net.URI getTargetURL()

This will return the URL existing in a slide of the presentation.

2

void setAddress(java.lang.String address)

This method is used to set address to a URL.

3

void setAddress(XSLFSlide slide)

This will set the address to the URL present in a slide of the presentation.


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