Apache Poi Ppt 简明教程
Apache POI PPT - Classes and Methods
在本章中,我们将了解 Apache POI API 中的一些类和方法,这些方法对于使用 Java 程序处理 PPT 文件至关重要。
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
要创建和管理演示文稿,您有一个名为 XMLSlideShow 的类,该类位于包 org.apache.poi.xslf.usermodel 中。下面给出了此类的某些重要方法和一个构造函数。
To create and manage a presentation, you have a class called XMLSlideShow in the package org.apache.poi.xslf.usermodel. Given below are some important methods and a constructor of this class.
Class − XMLSlideShow
Class − XMLSlideShow
Package − org.apache.poi.xslf.usermodel
Package − org.apache.poi.xslf.usermodel
S.No |
Constructor & Description |
1 |
XMLSlideShow(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 |
XSLFSlide createSlide() Creates a blank slide in a presentation. |
3 |
XSLFSlide createSlide(XSLFSlideLayout layout) Creates a slide with a given slide 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<XSLFSlideMaster> getSlideMasters() Returns the list of all the slides in a presentation. |
7 |
java.util.List<XSLFSlide> getSlides() Returns all the slides in a presentation. |
8 |
XSLFSlide removeSlide(int index) Using this method, you can remove a slide from a presentation. |
9 |
void setPageSize(java.awt.Dimension pgSize) Using this method, you can reset the page size. |
10 |
void setSlideOrder(XSLFSlide slide, int newIndex) Using this method, you can reorder the slides. |
Slide
如需在演示文稿中创建和管理幻灯片,请使用 XSLFSlide 类的相关方法。该类中的一些重要方法如下所述。
To create and manage a slide in a presentation, the methods of the XSLFSlide class are used. Some important methods of this class are mentioned below.
Class − XSLFSlide
Class − XSLFSlide
Package − org.apache.poi.xslf.usermodel
Package − org.apache.poi.xslf.usermodel
S.No |
Method & Description |
1 |
XSLFBackground getBackground() Returns the XSLFBackground object which can be used to retrieve 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() Provides access to the XSLFSlideLayout object of the current slide. |
3 |
XSLFSlideMaster getSlideMaster() Provides access to the slide master of the current slide. |
4 |
XSLFTheme getTheme() Returns the XSLFTheme object of the current slide. |
5 |
java.lang.String getTitle() Returns the title of the current slide. |
6 |
XSLFSlide importContent(XSLFSheet src) Copies the contents of another slide to this slide. |
Slide Master
这是演示文稿的一个组件,具有不同的幻灯片布局。 XSLFSlideMaster 类可用于对其进行访问。该类的部分重要方法如下所示。
It is the component of the presentation having different slide layouts. The XSLFSlideMaster class gives you access to it. Mentioned below are some important methods of this class.
Class − XSLFSlideMaster
Class − XSLFSlideMaster
Package − org.apache.poi.xslf.usermodel
Package − org.apache.poi.xslf.usermodel
S.No |
Method & Description |
1 |
XSLFBackground getBackground() Returns the common background of the slide master. |
2 |
XSLFSlideLayout getLayout(SlideLayout type) Returns the XSLFSlideLayout object. |
3 |
java.util.List<XSLFSlideLayout> getSlideLayouts() Returns all the slide layouts in this slide master. |
Slide Layout
POI 库有一个名为 XSLFSlideLayout 的类,可用于管理幻灯片的布局。
The POI library has a class called XSLFSlideLayout, using which you can manage the layouts of a slide.
Class − XSLFSlideLayout
Class − XSLFSlideLayout
Package − org.apache.poi.xslf.usermodel
Package − org.apache.poi.xslf.usermodel
S.No |
Method & Description |
1 |
void copyLayout(XSLFSlide slide) This method will copy the placeholders from this layout to the given slide. |
Text Paragraph
可以使用 XSLFTextParagraph 类向幻灯片写入内容。下面提到了该类的部分重要方法。
You can write content to the slide using XSLFTextParagraph class. Below mentioned are some important methods of this class.
Class − XSLFTextParagraph
Class − XSLFTextParagraph
Package − org.apache.poi.xslf.usermodel
Package − org.apache.poi.xslf.usermodel
S.No |
Method & Description |
1 |
XSLFTextRun addLineBreak() Inserts a line break in a paragraph. |
2 |
XSLFTextRun addNewTextRun() Adds a new run of text in a paragraph. |
3 |
void setBulletAutoNumber(ListAutoNumber scheme, int startAt) Applies 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 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
这是文本主体中文本分隔的最低级别。您可以通过 XSLFTextRun 类来管理段落的文本段。下面提到了该类的部分重要方法。
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
Class − XSLFTextParagraph
Package − org.apache.poi.xslf.usermodel
Package − org.apache.poi.xslf.usermodel
S.No |
Method & Description |
1 |
XSLFHyperlink createHyperlink() Creates a hyperlink in the presentation. |
2 |
XSLFHyperlink getHyperlink() This method is used to get the hyperlink. |
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 setItalic(boolean italic) This method is used to make the paragraph italicized. |
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 setUnderline(boolean underline) This method is used to underline the text in a text run. |
Text shape
在 PPT 中,我们有可以容纳文本的形状。我们可以使用 XSLFTextShape 类来管理它们。下面提到了此类的一些重要方法。
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
Class − XSLFTextShape
Package − org.apache.poi.xslf.usermodel
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 slide. |
HyperLink
POI 库有一个名为 XSLFHyperlink 的类,您可以使用它在演示文稿中创建一个超链接。下面提到了此类的一些重要方法。
The POI library has a class called XSLFHyperlink using which you can create a hyperlink in the presentation. Mentioned below are some important methods of this class.
Class − XSLFHyperlink
Class − XSLFHyperlink
Package − org.apache.poi.xslf.usermodel
Package − org.apache.poi.xslf.usermodel
S.No |
Method & Description |
1 |
java.net.URI getTargetURL() Returns 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) Sets address to the URL present in a slide of the presentation. |