文檔首頁>>E-iceblue中文文檔>>將復選框和圖片內(nèi)容控件添加到 Word 文檔
將復選框和圖片內(nèi)容控件添加到 Word 文檔
除了Combo Box、Text、Date Picker 和 Drop-Down List 內(nèi)容控件外,Checkbox 和圖片內(nèi)容控件也是 Word 文檔中使用最多的內(nèi)容控件。Spire.Doc 支持在word文檔中添加多種內(nèi)容控件。本文將向您展示如何通過 Spire.Doc for .NET 在 word 文檔中添加復選框和圖片內(nèi)容控件。
如何添加復選框和圖片內(nèi)容控件的代碼片段:
using System; using System.Drawing; namespace AddCheckbox { class Program { static void Main(string[] args) { //Create a new word document Document document = new Document(); //Add a section to the document Section section = document.AddSection(); //Add a document to the section Paragraph paragraph = section.AddParagraph(); //Add checkbox content control StructureDocumentTagInline sdt = new StructureDocumentTagInline(document); paragraph = section.AddParagraph(); sdt = new StructureDocumentTagInline(document); sdt.CharacterFormat.FontSize = 20; paragraph.ChildObjects.Add(sdt); sdt.SDTProperties.SDTType = SdtType.CheckBox; SdtCheckBox scb = new SdtCheckBox(); sdt.SDTProperties.ControlProperties = scb; TextRange tr = new TextRange(document); tr.CharacterFormat.FontName = "MS Gothic"; tr.CharacterFormat.FontSize = 20; sdt.ChildObjects.Add(tr); scb.Checked = true; sdt.SDTProperties.Alias = "CheckoBox"; sdt.SDTProperties.Tag = "Checkbox"; //Add picture content control paragraph = section.AddParagraph(); sdt = new StructureDocumentTagInline(document); paragraph.ChildObjects.Add(sdt); sdt.SDTProperties.ControlProperties = new SdtPicture(); sdt.SDTProperties.Alias = "Picture"; sdt.SDTProperties.Tag = "Picture"; DocPicture pic = new DocPicture(document) { Width = 10, Height = 10 }; pic.LoadImage(Image.FromFile("Logo.jpg")); sdt.SDTContent.ChildObjects.Add(pic); document.SaveToFile("Sample.docx", FileFormat.Docx2013); } } }
word文檔添加復選框和圖片內(nèi)容控件后的有效截圖:
歡迎下載|體驗更多E-iceblue產(chǎn)品
如需獲取更多產(chǎn)品相關信息請咨詢慧都在線客服