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