FieldAutoText

FieldAutoText class

实现自动文本字段。

要了解更多信息,请访问使用字段文档文章。

public class FieldAutoText : Field

构造函数

姓名描述
FieldAutoText()默认构造函数。

特性

姓名描述
DisplayResult { get; }获取表示显示的字段结果的文本。
End { get; }获取表示字段结束的节点。
EntryName { get; set; }获取或设置自动图文集条目的名称。
Format { get; }获得FieldFormat提供对字段格式的类型化访问的对象。
IsDirty { get; set; }获取或设置字段的当前结果是否由于对文档进行的其他修改而不再正确(陈旧)。
IsLocked { get; set; }获取或设置字段是否被锁定(不应重新计算其结果)。
LocaleId { get; set; }获取或设置字段的 LCID。
Result { get; set; }获取或设置字段分隔符和字段结束之间的文本。
Separator { get; }获取表示字段分隔符的节点。可无效的.
Start { get; }获取表示字段开始的节点。
virtual Type { get; }获取 Microsoft Word 字段类型。

方法

姓名描述
GetFieldCode()返回字段开始和字段分隔符之间的文本(如果没有分隔符,则返回字段结束)。 包括子字段的字段代码和字段结果。
GetFieldCode(bool)返回字段开始和字段分隔符之间的文本(如果没有分隔符,则返回字段结束)。
Remove()从文档中删除该字段。返回字段后面的节点。如果字段的结尾是其父节点的最后一个 child ,则返回其父段落。如果该字段已被删除,则返回无效的.
Unlink()执行字段取消链接。
Update()执行字段更新。如果该字段已被更新,则抛出异常。
Update(bool)执行字段更新。如果该字段已被更新,则抛出异常。

评论

插入自动图文集条目。

例子

演示如何显示带有自动文本和词汇表字段的构建块。

Document doc = new Document();

// 创建词汇表文档并向其中添加自动图文集构建块。
doc.GlossaryDocument = new GlossaryDocument();
BuildingBlock buildingBlock = new BuildingBlock(doc.GlossaryDocument);
buildingBlock.Name = "MyBlock";
buildingBlock.Gallery = BuildingBlockGallery.AutoText;
buildingBlock.Category = "General";
buildingBlock.Description = "MyBlock description";
buildingBlock.Behavior = BuildingBlockBehavior.Paragraph;
doc.GlossaryDocument.AppendChild(buildingBlock);

// 创建一个源并将其作为文本添加到我们的构建块中。
Document buildingBlockSource = new Document();
DocumentBuilder buildingBlockSourceBuilder = new DocumentBuilder(buildingBlockSource);
buildingBlockSourceBuilder.Writeln("Hello World!");

Node buildingBlockContent = doc.GlossaryDocument.ImportNode(buildingBlockSource.FirstSection, true);
buildingBlock.AppendChild(buildingBlockContent);

// 设置一个文件,其中包含我们的文档或其附加模板可能不包含的部分。
doc.FieldOptions.BuiltInTemplatesPaths = new[] { MyDir + "Busniess brochure.dotx" };

DocumentBuilder builder = new DocumentBuilder(doc);

// 下面是使用字段来显示构建块内容的两种方法。
// 1 - 使用自动文本字段:
FieldAutoText fieldAutoText = (FieldAutoText)builder.InsertField(FieldType.FieldAutoText, true);
fieldAutoText.EntryName = "MyBlock";

Assert.AreEqual(" AUTOTEXT  MyBlock", fieldAutoText.GetFieldCode());

// 2 - 使用 GLOSSARY 字段:
FieldGlossary fieldGlossary = (FieldGlossary)builder.InsertField(FieldType.FieldGlossary, true);
fieldGlossary.EntryName = "MyBlock";

Assert.AreEqual(" GLOSSARY  MyBlock", fieldGlossary.GetFieldCode());

doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.AUTOTEXT.GLOSSARY.dotx");

也可以看看