制作一个高质量的 PowerPoint 演示文稿的关键之一就是幻灯片的内容要做到清晰、易读。而列表正是达成这个要求的最常见、最有效的排版方式。通过列表展示内容,不仅可以让信息的结构条理化,还能突出要点,提升整体的阅读体验。
在本篇指南中,我们将一起学习如何使用 Spire.Presentation for Java,在 Java 程序中为 PowerPoint 幻灯片创建不同类型的列表。通过这些示例,你可以灵活控制文本的呈现方式,让演示内容更加专业、直观。

安装 Spire.Presentation for Java
在开始之前,你需要先在 Java 项目中引入 Spire.Presentation for Java,以便后续通过代码创建和设置 PowerPoint 中的编号列表和项目符号列表。
引入 Spire.Presentation 最直接的方式是将 .jar 文件添加为项目依赖。你可以在官网下载 Spire.Presentation 安装包,并手动引入到工程中。
如果你的项目使用 Maven 进行依赖管理,也可以在 pom.xml 文件中添加对应的依赖配置,即可快速集成 Spire.Presentation,从而在 Java 程序中灵活地创建和控制幻灯片中的列表样式。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>11.1.3</version>
</dependency>
</dependencies>
Java 在 PowerPoint 中创建编号列表
在编辑幻灯片上的内容时,编号列表非常适合用来展示有先后顺序的步骤流程或有逻辑递进关系的内容,比如项目的操作步骤、工作流程或注意事项等。通过在段落前自动添加编号,可以帮助观众快速理解信息的结构,让 PowerPoint 的演示内容更加清晰专业。
下面我们来看怎样使用 Spire.Presentation 在 PowerPoint 演示文稿中创建一个编号列表:
- 创建一个 Presentation 类的实例,并使用 Presentation.getSlides().get() 方法获取一张幻灯片。
- 通过 ISlide.getShapes().appendShape() 方法向幻灯片中添加一个形状,用于承载文本内容。
- 使用 String 列表来定义需要显示的列表文本。
- 根据列表内容创建多个段落,并通过 ParagraphEx.setBulletType() 方法将这些段落的项目符号类型设置为 NUMBERED。
- 使用 ParagraphEx.setBulletStyle() 方法设置编号的显示样式。
- 调用 Presentation.saveToFile() 方法,将文档保存为 PowerPoint 文件。
下面是一个完整的代码示例,展示了怎样使用 Java 在幻灯片上创建一个编号列表:
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class NumberedBullets {
public static void main(String[] args) throws Exception {
//创建 Presentation 实例
Presentation ppt = new Presentation();
//获取第一张幻灯片
ISlide slide = ppt.getSlides().get(0);
Rectangle2D rect = new Rectangle2D.Double(50, 70, 300, 200);
//添加一个形状到幻灯片
IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, rect);
shape.getShapeStyle().getLineColor().setColor(Color.white);
shape.getFill().setFillType(FillFormatType.NONE);
//移除形状中的默认段落
shape.getTextFrame().getParagraphs().clear();
String[] str = new String[] {"Item 1", "Item 2", "Item 3"};
//添加段落并设置列表格式为编号列表
for(int i = 0; i < str.length; i ++)
{
ParagraphEx paragraph = new ParagraphEx();
paragraph.setText(str[i]);
paragraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
paragraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
paragraph.setBulletType(TextBulletType.NUMBERED);
paragraph.setBulletStyle(NumberedBulletStyle.BULLET_ROMAN_LC_PERIOD);
shape.getTextFrame().getParagraphs().append(paragraph);
}
//保存文档
ppt.saveToFile("NumberedBullets.pptx", FileFormat.PPTX_2013);
}
}
输出文件预览:

为了让编号列表显示得更整齐,你还可以通过设置幻灯片的段落缩进与间距,对文本信息进行排版优化。
在 Java 中创建使用符号的项目列表
在 PowerPoint 中,列表的项目符号不仅可以是数字,也可以是符号或图片。其中,使用符号的项目列表是最常见的一种形式,通常使用圆点、方块等内置符号来标记每一条内容,适合用于展示并列要点、功能说明或概念列表。
在 Spire.Presentation for Java 中,只需将段落的项目符号类型设置为 SYMBOL,即可快速生成使用符号的列表。
下面是在 PowerPoint 中创建一个使用符号的项目列表:
- 创建一个 Presentation 对象。
- 使用 Presentation.getSlides().get() 方法获取第一张幻灯片。
- 通过 ISlide.getShapes().appendShape() 方法向幻灯片中添加一个形状,用于放置列表文本。
- 使用 String 列表定义列表的内容。
- 根据列表内容创建段落,并通过 ParagraphEx.setBulletType() 方法将这些段落的项目符号类型设置为 SYMBOL。
- 调用 Presentation.saveToFile() 方法,将文档保存为 PowerPoint 文件。
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class SymbolBullets {
public static void main(String[] args) throws Exception {
//创建 Presentation 实例
Presentation ppt = new Presentation();
//获取第一张幻灯片
ISlide slide = ppt.getSlides().get(0);
Rectangle2D rect = new Rectangle2D.Double(50, 70, 300, 200);
//添加一个形状到幻灯片
IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, rect);
shape.getShapeStyle().getLineColor().setColor(Color.white);
shape.getFill().setFillType(FillFormatType.NONE);
//清除形状中的默认段落
shape.getTextFrame().getParagraphs().clear();
String[] str = new String[] {"Item 1", "Item 2", "Item 3"};
//添加段落到形状并设置列表格式为项目符号
for(int i = 0; i < str.length; i ++)
{
ParagraphEx paragraph = new ParagraphEx();
paragraph.setText(str[i]);
paragraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
paragraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
paragraph.setBulletType(TextBulletType.SYMBOL);
shape.getTextFrame().getParagraphs().append(paragraph);
}
//保存文档
ppt.saveToFile("SymbolBullets.pptx", FileFormat.PPTX_2013);
}
}
结果文件预览:

在 Java 中创建以图片为符号的项目列表
在 PowerPoint 中,除了使用系统自带的符号作为列表标志外,你还可以自定义项目符号的样式,比如使用图片作为项目符号,让列表在视觉上更加醒目、个性化。图片项目符号更适合用于品牌展示、重点强调或需要增强视觉识别度的场景,例如产品优势说明、功能亮点展示等。
在 Spire.Presentation for Java 中,要创建以图片为符号的项目列表,需要将项目符号类型设置为 PICTURE,并为 BulletPicture 对象指定一张图片。下面是具体的实现步骤:
- 创建一个 Presentation 对象。
- 使用 Presentation.getSlides().get() 方法获取第一张幻灯片。
- 通过 ISlide.getShapes().appendShape() 方法向幻灯片中添加一个形状,用于承载列表文本。
- 使用 String 列表定义项目符号列表的内容。
- 根据列表内容创建段落,并通过 ParagraphEx.setBulletType() 方法将这些段落的项目符号类型设置为 PICTURE。
- 调用 Paragraph.getBulletPicture().setEmbedImage() 方法,为项目符号设置对应的图片。
- 使用 Presentation.saveToFile() 方法将文档保存为 PowerPoint 文件。
下面的代码展示了怎样使用图片作为符号创建一个待办事项列表:
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
public class CreateBulletedListWithImage {
public static void main(String[] args) throws Exception {
//创建一个 Presentation 类的对象
Presentation presentation = new Presentation();
presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);
//获取第一页幻灯片
ISlide slide = presentation.getSlides().get(0);
//在幻灯片中添加一个形状
Rectangle2D rect = new Rectangle2D.Double(50, 50, 400, 180);
IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, rect);
shape.getLine().setFillType(FillFormatType.NONE);
shape.getFill().setFillType(FillFormatType.NONE);
//添加文本到默认段落
ParagraphEx titleParagraph = shape.getTextFrame().getParagraphs().get(0);
titleParagraph.setText("项目待办事项:");
titleParagraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
titleParagraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
titleParagraph.setAlignment(TextAlignmentType.LEFT);
//自定义列表内容
String[] listContent = new String[] {
" 确认你想要做的项目和任务",
" 分配人员任务",
" 确定任务的优先级",
" 跟踪任务的进度状态",
" 完成任务后进行标记"
};
//创建以图片为符号的符号项目列表
BufferedImage image = ImageIO.read(new File("/check.png"));
for(int i = 0; i < listContent.length; i ++)
{
ParagraphEx paragraph = new ParagraphEx();
shape.getTextFrame().getParagraphs().append(paragraph);
paragraph.setText(listContent[i]);
paragraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
paragraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
paragraph.setBulletType(TextBulletType.PICTURE);
paragraph.getBulletPicture().setEmbedImage(presentation.getImages().append(image));
}
//保存文档
presentation.saveToFile("/output/图片符号.pptx", FileFormat.PPTX_2013);
}
}
输出文件预览:

结语
通过以上示例,你已经了解了如何使用 Spire.Presentation 在 PowerPoint 文件中创建编号列表和项目符号列表。掌握这些技能,你可以通过代码灵活控制幻灯片中文本的结构和呈现方式,让演示内容更加清晰、专业且富有表现力。
如果你对 Spire.Presentation for Java 感兴趣,不妨下载试试看。如果有任何问题,请随时联系我们获取技术支持和指导。







