Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。
E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式
Spire.Doc for.NET 最新下载(qun:767755948)https://www.evget.com/product/3368/download
该文将介绍如何在.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
效果图:
以上便是在.NET应用程序中使用象征符号绘制复选框到Word文档,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。