翻譯|使用教程|編輯:胡濤|2023-06-07 09:42:38.970|閱讀 141 次
概述:該文將介紹如何在.NET應用程序中使用象征符號繪制復選框到Word文檔,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
該文將介紹如何在.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文檔,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn