本文将介绍如何使用spire.doc for java在word文档中创建简单的项目符号列表和编号列表。
import com.spire.doc.*;
import com.spire.doc.documents.*;
public class bulletedlist {
public static void main(string[] args){
//加载word文档
document document = new document();
//添加一个section
section section = document.addsection();
//添加8个段落
paragraph paragraph1 = section.addparagraph();
paragraph1.appendtext("项目符号列表");
paragraph1.applystyle(builtinstyle.heading_1);
paragraph paragraph2 = section.addparagraph();
paragraph2.appendtext("第一章");
paragraph paragraph3 = section.addparagraph();
paragraph3.appendtext("第二章");
paragraph paragraph4 = section.addparagraph();
paragraph4.appendtext("第三章");
paragraph paragraph5 = section.addparagraph();
paragraph5.appendtext("编号列表");
paragraph5.applystyle(builtinstyle.heading_1);
paragraph paragraph6 = section.addparagraph();
paragraph6.appendtext("第一章");
paragraph paragraph7 = section.addparagraph();
paragraph7.appendtext("第二章");
paragraph paragraph8 = section.addparagraph();
paragraph8.appendtext("第三章");
//给第2到第4个段落应用项目符号列表格式
for(int i = 1; i < 4; i ){
paragraph para = section.getparagraphs().get(i);
para.getlistformat().applybulletstyle();
para.getlistformat().getcurrentlistlevel().setnumberposition(-10);
}
//给第6到第8个段落应用编号列表格式
for(int i = 5; i < 8; i ){
paragraph para = section.getparagraphs().get(i);
para.getlistformat().applynumberedstyle();
para.getlistformat().getcurrentlistlevel().setnumberposition(-10);
}
//保存文档
document.savetofile("createlists.docx", fileformat.docx_2013);
}
}
生成文档: