Thetype exposes the following members.
Gets the text that represents the displayed field result.
Gets the node that represents the field end.
Gets a FieldFormat object that provides typed access to field's formatting.
Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
Gets or sets whether the field is locked (should not recalculate its result).
Gets or sets the LCID of the field.
Gets or sets text that is between the field separator and field end.
Gets the node that represents the field separator. Can be null.
Gets the node that represents the start of the field.
Gets the Microsoft Word field type.
|Equals||(Inherited from Object.)|
Returns text between field start and field separator (or field end if there is no separator). Both field code and field result of child fields are included.
Returns text between field start and field separator (or field end if there is no separator).
|GetHashCode||(Inherited from Object.)|
|GetType||(Inherited from Object.)|
Removes the field from the document. Returns a node right after the field. If the field's end is the last child of its parent node, returns its parent paragraph. If the field is already removed, returns null.
|ToString||(Inherited from Object.)|
Performs the field unlink.
Performs the field update. Throws if the field is being updated already.
Performs a field update. Throws if the field is being updated already.
A field in a Word document is a complex structure consisting of multiple nodes that include field start, field code, field separator, field result and field end. Fields can be nested, contain rich content and span multiple paragraphs or sections in a document. Theclass is a "facade" object that provides properties and methods that allow to work with a field as a single object.
The content between the field start and separator is the field code. The content between the field separator and field end is the field result. The field code typically consists of one or more Run objects that specify instructions. The processing application is expected to execute the field code to calculate the field result.
The process of calculating field results is called the field update. Aspose.Words can update field results of most of the field types in exactly the same way as Microsoft Word does it. Most notably, Aspose.Words can calculate results of even the most complex formula fields. To calculate the field result of a single field use the Update method. To update fields in the whole document use UpdateFields.
You can get the plain text version of the field code using the GetFieldCode(Boolean) method. You can get and set the plain text version of the field result using the Result property. Both the field code and field result can contain complex content, such as nested fields, paragraphs, shapes, tables and in this case you might want to work with the field nodes directly if you need more control.
You do not create instances of the InsertField(String) method.class directly. To create a new field use the
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a simple Date field into the document // When we insert a field through the DocumentBuilder class we can get the // special Field object which contains information about the field Field dateField = builder.InsertField(@"DATE \* MERGEFORMAT"); // Update this particular field in the document so we can get the FieldResult dateField.Update(); // Display some information from this field // The field result is where the last evaluated value is stored. This is what is displayed in the document // When field codes are not showing Assert.AreEqual(DateTime.Today, DateTime.Parse(dateField.Result)); // Display the field code which defines the behavior of the field. This can been seen in Microsoft Word by pressing ALT+F9 Assert.AreEqual(@"DATE \* MERGEFORMAT", dateField.GetFieldCode()); // The field type defines what type of field in the Document this is. In this case the type is "FieldDate" Assert.AreEqual(FieldType.FieldDate, dateField.Type); // Finally let's completely remove the field from the document. This can easily be done by invoking the Remove method on the object dateField.Remove();