该文将介绍如何在.net应用程序中使用象征符号绘制复选框到word文档。
c#
using spire.doc;
using spire.doc.documents;
using spire.doc.fields;
using system.drawing;
using system.collections.generic;
namespace checkbox
{
class program
{
static void main(string[] args)
{
//新建word实例,添加section,段落并插入文本
document doc = new document();
section sec = doc.addsection();
paragraph para = sec.addparagraph();
para.appendtext("指定字符替换成复选框, symbol1, symbol2, symbol3.");
//设置段落样式
paragraphstyle style = new paragraphstyle(doc);
style.name = "parastyle";
style.characterformat.fontname = "宋体";
style.characterformat.fontsize = 11;
doc.styles.add(style);
para.applystyle("parastyle");
//复选框打勾
textselection selection1 = doc.findstring("symbol1", true, true);
textrange tr1 = selection1.getasonerange();
tr1.characterformat.fontname = "wingdings 2";
//doc.replace(selection1.selectedtext, "\u0052", true, true);
//16进制复选框打勾是0052,10进制复选框打勾是82
doc.replace(selection1.selectedtext, ((char)82).tostring(), true, true);
//复选框打叉
textselection selection2 = doc.findstring("symbol2", true, true);
textrange tr2 = selection2.getasonerange();
tr2.characterformat.fontname = "wingdings 2";
//16进制复选框打叉是0053,10进制复选框打叉是83
doc.replace(selection2.selectedtext, "\u0053", true, true);
//复选框不勾选
textselection selection3 = doc.findstring("symbol3", true, true);
textrange tr3 = selection3.getasonerange();
tr3.characterformat.fontname="wingdings 2";
//16进制复选框不勾选是00a3,10进制是163
doc.replace(selection3.selectedtext, "\u00a3", true, true);
//保存文档
doc.savetofile("symboltest.docx",fileformat.docx2013);
}
}
}
vb.net
imports spire.doc
imports spire.doc.documents
imports spire.doc.fields
imports system.drawing
imports system.collections.generic
namespace checkbox
class program
private shared sub main(byval args() as string)
dim doc as document = new document
dim sec as section = doc.addsection
dim para as paragraph = sec.addparagraph
para.appendtext("指定字符替换成复选框, symbol1, symbol2, symbol3.”),
paragraphstyle, style=newparagraphstyle(docunknown)
style.name = "parastyle"
style.characterformat.fontname = "宋体"
style.characterformat.fontsize = 11
doc.styles.add(style)
para.applystyle("parastyle")
'复选框打勾
dim selection1 as textselection = doc.findstring("symbol1", true, true)
dim tr1 as textrange = selection1.getasonerange
tr1.characterformat.fontname = "wingdings 2"
'16进制复选框打勾是0052,10进制复选框打勾是82
'doc.replace(selection1.selectedtext, "\u0052", true, true);
doc.replace(selection1.selectedtext, ctype(82,char).tostring, true, true)
'复选框打叉
dim selection2 as textselection = doc.findstring("symbol2", true, true)
dim tr2 as textrange = selection2.getasonerange
tr2.characterformat.fontname = "wingdings 2"
'16进制复选框打叉是0053,10进制复选框打叉是83
doc.replace(selection2.selectedtext, "\u0053", true, true)
'复选框不勾选
dim selection3 as textselection = doc.findstring("symbol3", true, true)
dim tr3 as textrange = selection3.getasonerange
tr3.characterformat.fontname = "wingdings 2"
'16进制复选框不勾选是00a3,10进制是163
doc.replace(selection3.selectedtext, "\u00a3", true, true)
'保存文档
doc.savetofile("symboltest.docx", fileformat.docx2013)
end sub
end class
end namespace
效果图: