📅  最后修改于: 2020-11-18 08:49:23             🧑  作者: Mango
在本章中,我们将学习Apache POI API下的一些类和方法,这些类和方法对于使用Java程序处理PPT文件至关重要。
要创建和管理演示文稿,必须在org.apache.poi.xslf.usermodel包中包含一个名为XMLSlideShow的类。下面给出了一些重要的方法和该类的构造函数。
类-XMLSlideShow
包-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 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 |
XSLFSlideMaster[] getSlideMasters() Returns the array of all the slides in a presentation. |
7 |
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. |
要在演示文稿中创建和管理幻灯片,请使用XSLFSlide类的方法。此类中的一些重要方法在下面提到。
类-XSLFSlide
包-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. |
它是演示文稿的组成部分,具有不同的幻灯片布局。 XSLFSlideMaster类使您可以访问它。下面提到的是此类的一些重要方法。
类-XSLFSlideMaster
包-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 |
XSLFSlideLayout[] getSlideLayouts() Returns all the slide layouts in this slide master. |
POI库具有一个名为XSLFSlideLayout的类,您可以使用该类来管理幻灯片的布局。
类-XSLFSlideLayout
包-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. |
您可以使用XSLFTextParagraph类将内容写入幻灯片。下面提到的是此类的一些重要方法。
类-XSLFTextParagraph
包-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. |
这是文本主体中最低级别的文本分离。您具有XSLFTextRun类来管理段落的文本运行。下面提到的是此类的一些重要方法。
类-XSLFTextParagraph
包-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. |
在PPT中,我们具有可以在其中保存文本的形状。我们可以使用XSLFTextShape类来管理它们。下面提到的是此类的一些重要方法。
类-XSLFTextShape
包-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. |
POI库具有一个名为XSLFHyperlink的类,您可以使用该类在演示文稿中创建超链接。下面提到的是此类的一些重要方法。
类-XSLFHyperlink
包-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. |