Full width home advertisement

How To

Science

Post Page Advertisement [Top]


Apache POI (PowerPoint) Review

PowerPoint, as you may know, is a tool developed by Microsoft used for the creation of presentations in the form of slides. Marketers use it for creating captivating pitches, teachers use it to graphically communicate their ideas etc.

But it doesn’t end there – with Apache POI PowerPoint, a programmer can create astonishing presentation merely using Java.

Getting Started

The good first step to getting started with PowerPoint Presentation is creating a new file, and to do this you will need to call the XMLSlideShow function using the following line of code:

XMLSlideShow ppt = new XMLSlideShow();

Next is to create a new PowerPoint document – the code below should get the job done

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()
}
}

Creating and editing slides in PowerPoint using Apache POI
To create a new slide in PowerPoint using Java, call the XSLFSlide Function. Other functions you will need as you work are:

XSLFBackground getBackground(): This function is used for formatting the background of slides in PowerPoint. It lets a user specify background colour and use an image as background.

XSLFSlideLayout getSlideLayout(): Lets a user modify and edit the layout of a particular slide.

XSLFSlide importContent(XSLFSheet src: To extract the properties of a particular slide and copy them unto another.

When working on a presentation, the need to write and edit texts may arise. Not to worry –Apache POI has got some cool tool to handle this. Here are some of the functions and what they do:

· XSLFTextRun addLineBreak(): For inserting line breaks when starting a new paragraph

· void setIndent(double value): For adding indentation to a block of text

· void setTextAlign(TextAlign align): Does the job of text alignment.

· void setBold(boolean bold): For bolding texts

· void setFontSize(double fontSize): Does the work of setting font size. 

Apache POI (PowerPoint) Tutorial: 

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib