本文将介绍如何使用spire.doc来设置文字效果,包括文本边框,文本填充,文字阴影等。
c#
//实例化一个document对象
document doc = new document();
//向文档中添加一个section对象
section sec = doc.addsection();
//在这个section上添加一个段落并给文字加边框
paragraph p1 = sec.addparagraph();
textrange tr1 = p1.appendtext("加粉色边框的文字");
tr1.characterformat.border.bordertype = borderstyle.dashdotstroker;
tr1.characterformat.border.color = color.pink;
p1.appendbreak(breaktype.linebreak);
//添加一个新段落并设置文字填充效果
paragraph p2 = sec.addparagraph();
textrange tr2 = p2.appendtext("设置填充效果的文字");
//设置文字前景色
tr2.characterformat.textcolor = color.orange;
//设置文字背景色
tr2.characterformat.textbackgroundcolor = color.lightgray;
//设置文字缩放比例
tr2.characterformat.textscale = 150;
p2.appendbreak(breaktype.linebreak);
//添加一个新段落并设置阴影
paragraph p3 = sec.addparagraph();
textrange tr3 = p3.appendtext("设置阴影效果的文字");
tr3.characterformat.textcolor = color.lightseagreen;
tr3.characterformat.isshadow = true;
p3.appendbreak(breaktype.linebreak);
//添加一个新段落并设置简单的文字样式
paragraph p4 = sec.addparagraph();
textrange tr4 = p4.appendtext("设置删除线效果的文字");
tr4.characterformat.isstrikeout = true;
p4.appendbreak(breaktype.linebreak);
textrange tr5 = p4.appendtext("设置文字大写: hello, e-iceblue.");
tr5.characterformat.issmallcaps = true;
//使用clearformatting()来删除某个textrange的文字效果
//tr5.characterformat.clearformatting();
//保存文档
doc.savetofile("文字效果.docx");
vb.net
'实例化一个document对象
dim doc as document = new document
'向文档中添加一个section对象
dim sec as section = doc.addsection
'在这个section上添加一个段落并给文字加边框
dim p1 as paragraph = sec.addparagraph
dim tr1 as textrange = p1.appendtext("加粉色边框的文字")
tr1.characterformat.border.bordertype = borderstyle.dashdotstroker
tr1.characterformat.border.color = color.pink
p1.appendbreak(breaktype.linebreak)
'添加一个新段落并设置文字填充效果
dim p2 as paragraph = sec.addparagraph
dim tr2 as textrange = p2.appendtext("设置填充效果的文字")
'设置文字前景色
tr2.characterformat.textcolor = color.orange
'设置文字背景色
tr2.characterformat.textbackgroundcolor = color.lightgray
'设置文字缩放比例
tr2.characterformat.textscale = 150
p2.appendbreak(breaktype.linebreak)
'添加一个新段落并设置阴影
dim p3 as paragraph = sec.addparagraph
dim tr3 as textrange = p3.appendtext("设置阴影效果的文字")
tr3.characterformat.textcolor = color.lightseagreen
tr3.characterformat.isshadow = true
p3.appendbreak(breaktype.linebreak)
'添加一个新段落并设置简单的文字样式
dim p4 as paragraph = sec.addparagraph
dim tr4 as textrange = p4.appendtext("设置删除线效果的文字")
tr4.characterformat.isstrikeout = true
p4.appendbreak(breaktype.linebreak)
dim tr5 as textrange = p4.appendtext("设置文字大写: hello, e-iceblue.")
tr5.characterformat.issmallcaps = true
'使用clearformatting()来删除某个textrange的文字效果
'tr5.characterformat.clearformatting();
'保存文档
doc.savetofile("文字效果.docx")
效果图如下: