本文将介绍如何使用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);
}
}