Word控件Spire.Doc 【文档操作】教程(十七、十八):在 C# 中将复选框和图片内容控件添加到 Word 文档 /C# 将数学方程式和符号插入 Word 文档

 在 C# 中将复选框和图片内容控件添加到 Word 文档 


除了Combo Box、Text、Date Picker 和 Drop-Down List 内容控件外,Checkbox 和图片内容控件也是 Word 文档中使用最多的内容控件。Spire.Doc 支持在word文档中添加多种内容控件。本文将向您展示如何通过 Spire.Doc for .NET 在 word 文档中添加复选框和图片内容控件。

Spire.Doc for.NET 最新下载

如何添加复选框和图片内容控件的代码片段:

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文档添加复选框和图片内容控件后的有效截图: 

C# 将数学方程式和符号插入 Word 文档 

从 7.6.5 版本开始,Spire.Doc 支持将 Latex 数学代码添加到 C# 中的 Word 文档中。本文将向您展示如何将 Latex 数学符号和方程式添加到 Word 文档中。

Spire.Doc for.NET 最新下载

展示代码:

using Spire.Doc;
using Spire.Doc.Documents;
using System;
namespace InsertMath;

class Program
{

static void Main(string[] args)
{
//create a word document
Document doc = new Document();

//add a section
Section section = doc.AddSection();

//add a paragraph to the section
Paragraph paragraph = section.AddParagraph();

//add a LatexMathcode to the first paragraph
OfficeMath officeMath = new OfficeMath(doc);
paragraph.Items.Add(officeMath);
officeMath.FromLatexMathCode("x^{2}+\\sqrt{x^{2}+1}=2");

//add equation to the second paragraph
Paragraph paragraph2 = section.AddParagraph();
OfficeMath officeMath1 = new OfficeMath(doc);
paragraph2.Items.Add(officeMath1);
officeMath1.FromLatexMathCode("\\forall x \\in X, \\quad \\exists y \\leq \\epsilon");

//add symbols to the third paragraph
Paragraph paragraph3 = section.AddParagraph();
OfficeMath officeMath2 = new OfficeMath(doc);
paragraph3.Items.Add(officeMath2);
officeMath2.FromLatexMathCode(" \\alpha,\\beta, \\gamma, \\Gamma, \\pi, \\Pi, \\phi, \\varphi, \\mu, \\Phi");

//save the document to file
doc.SaveToFile("Equation.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("Equation.docx");
}
}
}

将latex数学代码和符号添加到word文档后的有效截图:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值