该文将介绍如何在.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效果图:

 



 
					



