本文将介绍如何使用Spire.Presentation for Java在PowerPoint幻灯片中创建编号列表和项目符号列表。
创建编号列表
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);
}
}
添加项目符号列表
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);
}
}