本文介绍如何使用Spire.Doc for Java将ASCII字符设置为Word文档中的列表符号。
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.ListStyle;
import com.spire.doc.documents.ListType;
import com.spire.doc.documents.Paragraph;
public class SetBulletPoints {
public static void main(String[] args) {
//创建Document对象并添加节
Document doc = new Document();
Section section = doc.addSection();
//根据不同的ASCII字符创建四种不同的列表样式
ListStyle listStyle1 = new ListStyle(doc, ListType.Bulleted);
listStyle1.getLevels().get(0).setBulletCharacter("\u006e");
listStyle1.getLevels().get(0).getCharacterFormat().setFontName("Wingdings");
listStyle1.setName("liststyle1");
doc.getListStyles().add(listStyle1);
ListStyle listStyle2 = new ListStyle(doc, ListType.Bulleted);
listStyle2.getLevels().get(0).setBulletCharacter("\u0075");
listStyle2.getLevels().get(0).getCharacterFormat().setFontName("Wingdings");
listStyle2.setName("liststyle2");
doc.getListStyles().add(listStyle2);
ListStyle listStyle3 = new ListStyle(doc, ListType.Bulleted);
listStyle3.getLevels().get(0).setBulletCharacter("\u00b2");
listStyle3.getLevels().get(0).getCharacterFormat().setFontName("Wingdings");
listStyle3.setName("liststyle3");
doc.getListStyles().add(listStyle3);
ListStyle listStyle4 = new ListStyle(doc, ListType.Bulleted);
listStyle4 .getLevels().get(0).setBulletCharacter("\u00d8");
listStyle4 .getLevels().get(0).getCharacterFormat().setFontName("Wingdings");
listStyle4.setName("liststyle4");
doc.getListStyles().add(listStyle4);
//添加四个段落并分别应用列表样式
Paragraph p1 = section.getBody().addParagraph();
p1.appendText("Spire.Doc for .NET");
p1.getListFormat().applyStyle(listStyle1.getName());
Paragraph p2 = section.getBody().addParagraph();
p2.appendText("Spire.PDF for .NET");
p2.getListFormat().applyStyle(listStyle2.getName());
Paragraph p3 = section.getBody().addParagraph();
p3.appendText("Spire.XLS for .NET");
p3.getListFormat().applyStyle(listStyle3.getName());
Paragraph p4= section.getBody().addParagraph();
p4.appendText("Spire.Presentation for .NET");
p4.getListFormat().applyStyle(listStyle4.getName());
//保存到文档
doc.saveToFile("output/SetBulletCharacter.docx", FileFormat.Docx);
}
}