本文介绍如何使用Spire.Doc 将ASCII字符(特殊符号)设置为Word文档中的列表符号。
C#
using Spire.Doc;
using Spire.Doc.Documents;
namespace SetBulletCharacter
{
class Program
{
static void Main(string[] args)
{
//创建Document对象并添加一个section
Document doc = new Document();
Section section = doc.AddSection();
//根据不同的ASCII编码创建四个列表样式
ListStyle listStyle1 = new ListStyle(doc, ListType.Bulleted);
listStyle1.Name = "liststyle";
listStyle1.Levels[0].BulletCharacter = "\x006e";
listStyle1.Levels[0].CharacterFormat.FontName = "Wingdings";
doc.ListStyles.Add(listStyle1);
ListStyle listStyle2 = new ListStyle(doc, ListType.Bulleted);
listStyle2.Name = "liststyle2";
listStyle2.Levels[0].BulletCharacter = "\x0075";
listStyle2.Levels[0].CharacterFormat.FontName = "Wingdings";
doc.ListStyles.Add(listStyle2);
ListStyle listStyle3 = new ListStyle(doc, ListType.Bulleted);
listStyle3.Name = "liststyle3";
listStyle3.Levels[0].BulletCharacter = "\x00b2";
listStyle3.Levels[0].CharacterFormat.FontName = "Wingdings";
doc.ListStyles.Add(listStyle3);
ListStyle listStyle4 = new ListStyle(doc, ListType.Bulleted);
listStyle4.Name = "liststyle4";
listStyle4.Levels[0].BulletCharacter = "\x00d8";
listStyle4.Levels[0].CharacterFormat.FontName = "Wingdings";
doc.ListStyles.Add(listStyle4);
//添加四个段落并分别应用列表样式
Paragraph p1 = section.Body.AddParagraph();
p1.AppendText("Spire.Doc for .NET");
p1.ListFormat.ApplyStyle(listStyle1.Name);
Paragraph p2 = section.Body.AddParagraph();
p2.AppendText("Spire.PDF for .NET");
p2.ListFormat.ApplyStyle(listStyle2.Name);
Paragraph p3 = section.Body.AddParagraph();
p3.AppendText("Spire.XLS for .NET");
p3.ListFormat.ApplyStyle(listStyle3.Name);
Paragraph p4 = section.Body.AddParagraph();
p4.AppendText("Spire.Presentation for .NET");
p4.ListFormat.ApplyStyle(listStyle4.Name);
//保存文档
doc.SaveToFile("output.docx", FileFormat.Docx2013);
}
}
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace SetBulletCharacter
Class Program
Shared Sub Main(ByVal args() As String)
'创建Document对象并添加一个section
Document doc = New Document()
Dim section As Section = doc.AddSection()
'根据不同的ASCII编码创建四个列表样式
Dim listStyle1 As ListStyle = New ListStyle(doc, ListType.Bulleted)
listStyle1.Name = "liststyle"
listStyle1.Levels(0).BulletCharacter = "\x006e"
listStyle1.Levels(0).CharacterFormat.FontName = "Wingdings"
doc.ListStyles.Add(listStyle1)
Dim listStyle2 As ListStyle = New ListStyle(doc, ListType.Bulleted)
listStyle2.Name = "liststyle2"
listStyle2.Levels(0).BulletCharacter = "\x0075"
listStyle2.Levels(0).CharacterFormat.FontName = "Wingdings"
doc.ListStyles.Add(listStyle2)
Dim listStyle3 As ListStyle = New ListStyle(doc, ListType.Bulleted)
listStyle3.Name = "liststyle3"
listStyle3.Levels(0).BulletCharacter = "\x00b2"
listStyle3.Levels(0).CharacterFormat.FontName = "Wingdings"
doc.ListStyles.Add(listStyle3)
Dim listStyle4 As ListStyle = New ListStyle(doc, ListType.Bulleted)
listStyle4.Name = "liststyle4"
listStyle4.Levels(0).BulletCharacter = "\x00d8"
listStyle4.Levels(0).CharacterFormat.FontName = "Wingdings"
doc.ListStyles.Add(listStyle4)
'添加四个段落并分别应用列表样式
Dim p1 As Paragraph = section.Body.AddParagraph()
p1.AppendText("Spire.Doc for .NET")
p1.ListFormat.ApplyStyle(listStyle1.Name)
Dim p2 As Paragraph = section.Body.AddParagraph()
p2.AppendText("Spire.PDF for .NET")
p2.ListFormat.ApplyStyle(listStyle2.Name)
Dim p3 As Paragraph = section.Body.AddParagraph()
p3.AppendText("Spire.XLS for .NET")
p3.ListFormat.ApplyStyle(listStyle3.Name)
Dim p4 As Paragraph = section.Body.AddParagraph()
p4.AppendText("Spire.Presentation for .NET")
p4.ListFormat.ApplyStyle(listStyle4.Name)
'保存文档
doc.SaveToFile("output.docx", FileFormat.Docx2013)
End Sub
End Class
End Namespace