FieldSeparator Class |
Namespace: Aspose.Words.Fields
The FieldSeparator type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | Document |
Gets the document to which this node belongs.
(Inherited from Node.) |
![]() ![]() | FieldType |
Returns the type of the field.
(Inherited from FieldChar.) |
![]() ![]() | Font |
Provides access to the font formatting of this object.
(Inherited from Inline.) |
![]() ![]() | IsComposite |
Returns true if this node can contain other nodes.
(Inherited from Node.) |
![]() ![]() | IsDeleteRevision |
Returns true if this object was deleted in Microsoft Word while change tracking was enabled.
(Inherited from Inline.) |
![]() ![]() | IsDirty |
Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications
made to the document.
(Inherited from FieldChar.) |
![]() ![]() | IsFormatRevision |
Returns true if formatting of the object was changed in Microsoft Word while change tracking was enabled.
(Inherited from Inline.) |
![]() ![]() | IsInsertRevision |
Returns true if this object was inserted in Microsoft Word while change tracking was enabled.
(Inherited from Inline.) |
![]() ![]() | IsLocked |
Gets or sets whether the parent field is locked (should not recalculate its result).
(Inherited from FieldChar.) |
![]() ![]() | IsMoveFromRevision |
Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled.
(Inherited from Inline.) |
![]() ![]() | IsMoveToRevision |
Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled.
(Inherited from Inline.) |
![]() ![]() | NextSibling |
Gets the node immediately following this node.
(Inherited from Node.) |
![]() ![]() | NodeType |
Returns FieldSeparator.
(Overrides SpecialCharNodeType.) |
![]() ![]() | ParentNode |
Gets the immediate parent of this node.
(Inherited from Node.) |
![]() ![]() | ParentParagraph |
Retrieves the parent Paragraph of this node.
(Inherited from Inline.) |
![]() ![]() | PreviousSibling |
Gets the node immediately preceding this node.
(Inherited from Node.) |
![]() ![]() | Range |
Returns a Range object that represents the portion of a document that is contained in this node.
(Inherited from Node.) |
Name | Description | |
---|---|---|
![]() ![]() | Accept |
Accepts a visitor.
(Overrides SpecialCharAccept(DocumentVisitor).) |
![]() ![]() | Clone | (Inherited from Node.) |
![]() | Equals | (Inherited from Object.) |
![]() ![]() | GetAncestor(Type) |
Gets the first ancestor of the specified object type.
(Inherited from Node.) |
![]() ![]() | GetAncestor(NodeType) |
Gets the first ancestor of the specified NodeType.
(Inherited from Node.) |
![]() ![]() | GetField |
Returns a field for the field char.
(Inherited from FieldChar.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetText |
Gets the special character that this node represents.
(Inherited from SpecialChar.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | NextPreOrder |
Gets next node according to the pre-order tree traversal algorithm.
(Inherited from Node.) |
![]() ![]() | PreviousPreOrder |
Gets the previous node according to the pre-order tree traversal algorithm.
(Inherited from Node.) |
![]() ![]() | Remove |
Removes itself from the parent.
(Inherited from Node.) |
![]() | ToString | (Inherited from Object.) |
![]() ![]() | ToString(SaveFormat) |
Exports the content of the node into a string in the specified format.
(Inherited from Node.) |
![]() ![]() | ToString(SaveOptions) |
Exports the content of the node into a string using the specified save options.
(Inherited from Node.) |
FieldSeparator is an inline-level node and represented by the FieldSeparatorChar control character in the document.
FieldSeparator can only be a child of Paragraph.
A complete field in a Microsoft Word document is a complex structure consisting of a field start character, field code, field separator character, field result and field end character. Some fields only have field start, field code and field end.
To easily insert a new field into a document, use the InsertField(String) method.
public void FieldCollection() { // Create a new document and insert some fields Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.InsertField(" DATE \\@ \"dddd, d MMMM yyyy\" "); builder.InsertField(" TIME "); builder.InsertField(" REVNUM "); builder.InsertField(" AUTHOR \"John Doe\" "); builder.InsertField(" SUBJECT \"My Subject\" "); builder.InsertField(" QUOTE \"Hello world!\" "); doc.UpdateFields(); // Get the collection that contains all the fields in a document FieldCollection fields = doc.Range.Fields; Assert.AreEqual(6, fields.Count); // Iterate over the field collection and print contents and type of every field using a custom visitor implementation FieldVisitor fieldVisitor = new FieldVisitor(); using (IEnumerator<Field> fieldEnumerator = fields.GetEnumerator()) { while (fieldEnumerator.MoveNext()) { if (fieldEnumerator.Current != null) { fieldEnumerator.Current.Start.Accept(fieldVisitor); fieldEnumerator.Current.Separator?.Accept(fieldVisitor); fieldEnumerator.Current.End.Accept(fieldVisitor); } else { Console.WriteLine("There are no fields in the document."); } } } Console.WriteLine(fieldVisitor.GetText()); // Get a field to remove itself fields[0].Remove(); Assert.AreEqual(5, fields.Count); // Remove a field by reference Field lastField = fields[3]; fields.Remove(lastField); Assert.AreEqual(4, fields.Count); // Remove a field by index fields.RemoveAt(2); Assert.AreEqual(3, fields.Count); // Remove all fields from the document fields.Clear(); Assert.AreEqual(0, fields.Count); } /// <summary> /// Document visitor implementation that prints field info. /// </summary> public class FieldVisitor : DocumentVisitor { public FieldVisitor() { mBuilder = new StringBuilder(); } /// <summary> /// Gets the plain text of the document that was accumulated by the visitor. /// </summary> public string GetText() { return mBuilder.ToString(); } /// <summary> /// Called when a FieldStart node is encountered in the document. /// </summary> public override VisitorAction VisitFieldStart(FieldStart fieldStart) { mBuilder.AppendLine("Found field: " + fieldStart.FieldType); mBuilder.AppendLine("\tField code: " + fieldStart.GetField().GetFieldCode()); mBuilder.AppendLine("\tDisplayed as: " + fieldStart.GetField().Result); return VisitorAction.Continue; } /// <summary> /// Called when a FieldSeparator node is encountered in the document. /// </summary> public override VisitorAction VisitFieldSeparator(FieldSeparator fieldSeparator) { mBuilder.AppendLine("\tFound separator: " + fieldSeparator.GetText()); return VisitorAction.Continue; } /// <summary> /// Called when a FieldEnd node is encountered in the document. /// </summary> public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd) { mBuilder.AppendLine("End of field: " + fieldEnd.FieldType); return VisitorAction.Continue; } private readonly StringBuilder mBuilder; }