文档半岛外围网上直营>>E-iceblue中文文档>>将复选框和图片内容控件添加到 Word 文档
将复选框和图片内容控件添加到 Word 文档
除了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产品


QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线