翻譯|使用教程|編輯:胡濤|2022-04-19 13:25:48.110|閱讀 386 次
概述:本文將向您展示如何通過 Spire.Doc for .NET 在 word 文檔中添加復選框和圖片內容控件,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
除了Combo Box、Text、Date Picker 和 Drop-Down List 內容控件外,Checkbox 和圖片內容控件也是 Word 文檔中使用最多的內容控件。Spire.Doc 支持在word文檔中添加多種內容控件。本文將向您展示如何通過 Spire.Doc for .NET 在 word 文檔中添加復選框和圖片內容控件。
如何添加復選框和圖片內容控件的代碼片段:
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文檔添加復選框和圖片內容控件后的有效截圖:
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn