本文介绍如何使用Spire.Doc 将ASCII字符(特殊符号)设置为Word文档中的列表符号。
C#
//创建Document对象并添加一个section
Document doc = new Document();
Section section = doc.AddSection();
//根据不同的ASCII编码创建四个列表样式
ListStyle listStyle1 = doc.Styles.Add(ListType.Bulleted, "liststyle");
ListLevelCollection Levels1 = listStyle1.ListRef.Levels;
Levels1[0].BulletCharacter = "\x006e";
Levels1[0].CharacterFormat.FontName = "Wingdings";
ListStyle listStyle2 = doc.Styles.Add(ListType.Bulleted, "liststyle2");
ListLevelCollection Levels2 = listStyle2.ListRef.Levels;
Levels2[0].BulletCharacter = "\x0075";
Levels2[0].CharacterFormat.FontName = "Wingdings";
ListStyle listStyle3 = doc.Styles.Add(ListType.Bulleted, "liststyle2");
ListLevelCollection Levels3 = listStyle3.ListRef.Levels;
Levels3[0].BulletCharacter = "\x00b2";
Levels3[0].CharacterFormat.FontName = "Wingdings";
ListStyle listStyle4 = doc.Styles.Add(ListType.Bulleted, "liststyle2");
ListLevelCollection Levels4 = listStyle4.ListRef.Levels;
Levels4[0].BulletCharacter = "\x00d8";
Levels4[0].CharacterFormat.FontName = "Wingdings";
//添加四个段落并分别应用列表样式
Paragraph p1 = section.Body.AddParagraph();
p1.AppendText("Spire.Doc for .NET");
p1.ListFormat.ApplyStyle(listStyle1);
Paragraph p2 = section.Body.AddParagraph();
p2.AppendText("Spire.PDF for .NET");
p2.ListFormat.ApplyStyle(listStyle2);
Paragraph p3 = section.Body.AddParagraph();
p3.AppendText("Spire.XLS for .NET");
p3.ListFormat.ApplyStyle(listStyle3);
Paragraph p4 = section.Body.AddParagraph();
p4.AppendText("Spire.Presentation for .NET");
p4.ListFormat.ApplyStyle(listStyle4);
//保存文档
doc.SaveToFile("output.docx", FileFormat.Docx2013);
VB.NET
'创建Document对象并添加一个section Dim doc As New Document() Dim section As Section = doc.AddSection() '根据不同的ASCII编码创建四个列表样式
Dim listStyle1 As ListStyle = doc.Styles.Add(ListType.Bulleted, "liststyle")
Dim Levels1 As ListLevelCollection = listStyle1.ListRef.Levels
Levels1(0).BulletCharacter = ChrW(&H006e).ToString()
Levels1(0).CharacterFormat.FontName = "Wingdings"
Dim listStyle2 As ListStyle = doc.Styles.Add(ListType.Bulleted, "liststyle2")
Dim Levels2 As ListLevelCollection = listStyle2.ListRef.Levels
Levels2(0).BulletCharacter = ChrW(&H0075).ToString()
Levels2(0).CharacterFormat.FontName = "Wingdings"
Dim listStyle3 As ListStyle = doc.Styles.Add(ListType.Bulleted, "liststyle2")
Dim Levels3 As ListLevelCollection = listStyle3.ListRef.Levels
Levels3(0).BulletCharacter = ChrW(&H00b2).ToString()
Levels3(0).CharacterFormat.FontName = "Wingdings"
Dim listStyle4 As ListStyle = doc.Styles.Add(ListType.Bulleted, "liststyle2")
Dim Levels4 As ListLevelCollection = listStyle4.ListRef.Levels
Levels4(0).BulletCharacter = ChrW(&H00d8).ToString()
Levels4(0).CharacterFormat.FontName = "Wingdings"
'添加四个段落并分别应用列表样式 Dim p1 As Paragraph = section.Body.AddParagraph() p1.AppendText("Spire.Doc for .NET") p1.ListFormat.ApplyStyle(listStyle1) Dim p2 As Paragraph = section.Body.AddParagraph() p2.AppendText("Spire.PDF for .NET") p2.ListFormat.ApplyStyle(listStyle2) Dim p3 As Paragraph = section.Body.AddParagraph() p3.AppendText("Spire.XLS for .NET") p3.ListFormat.ApplyStyle(listStyle3) Dim p4 As Paragraph = section.Body.AddParagraph() p4.AppendText("Spire.Presentation for .NET") p4.ListFormat.ApplyStyle(listStyle4) '保存文档
doc.SaveToFile("output.docx", FileFormat.Docx2013)