public class Field
extends java.lang.Object
To learn more, visit the Working with Fields documentation article.
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. The Field class is a "facade" object that provides properties and methods that allow to work with a field as a single object.
The getStart(), getSeparator() and getEnd() properties point to the field start, separator and end nodes of the field respectively.
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 Document.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 getResult() / setResult(java.lang.String) 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 Field class directly. To create a new field use the DocumentBuilder.insertField(java.lang.String) method.
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getDisplayResult()
Gets the text that represents the displayed field result.
|
FieldEnd |
getEnd()
Gets the node that represents the field end.
|
java.lang.String |
getFieldCode()
Returns text between field start and field separator (or field end if there is no separator).
|
java.lang.String |
getFieldCode(boolean includeChildFieldCodes)
Returns text between field start and field separator (or field end if there is no separator).
|
FieldFormat |
getFormat()
Gets a
FieldFormat object that provides typed access to field's formatting. |
int |
getLocaleId()
Gets the LCID of the field.
|
java.lang.String |
getResult()
Gets text that is between the field separator and field end.
|
FieldSeparator |
getSeparator()
Gets the node that represents the field separator.
|
FieldStart |
getStart()
Gets the node that represents the start of the field.
|
int |
getType()
Gets the Microsoft Word field type.
|
boolean |
isDirty()
Gets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
|
void |
isDirty(boolean value)
Sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
|
boolean |
isLocked()
Gets whether the field is locked (should not recalculate its result).
|
void |
isLocked(boolean value)
Sets whether the field is locked (should not recalculate its result).
|
protected boolean |
needStoreOldResultNodes() |
Node |
remove()
Removes the field from the document.
|
void |
setLocaleId(int value)
Sets the LCID of the field.
|
void |
setResult(java.lang.String value)
Sets text that is between the field separator and field end.
|
boolean |
unlink()
Performs the field unlink.
|
void |
update()
Performs the field update.
|
void |
update(boolean ignoreMergeFormat)
Performs a field update.
|
public java.lang.String getFieldCode()
public java.lang.String getFieldCode(boolean includeChildFieldCodes)
includeChildFieldCodes - True if child field codes should be included.public Node remove() throws java.lang.Exception
java.lang.Exceptionpublic void update()
throws java.lang.Exception
java.lang.Exceptionpublic void update(boolean ignoreMergeFormat)
throws java.lang.Exception
ignoreMergeFormat - If true then direct field result formatting is abandoned, regardless of the MERGEFORMAT switch, otherwise normal update is performed.java.lang.Exceptionpublic boolean unlink()
throws java.lang.Exception
Replaces the field with its most recent result.
Some fields, such as XE (Index Entry) fields and SEQ (Sequence) fields, cannot be unlinked.
True if the field has been unlinked, otherwise false.java.lang.Exceptionprotected boolean needStoreOldResultNodes()
public FieldStart getStart()
public FieldSeparator getSeparator()
public FieldEnd getEnd()
public int getType()
FieldType constants.public java.lang.String getResult()
public void setResult(java.lang.String value)
throws java.lang.Exception
value - Text that is between the field separator and field end.java.lang.Exceptionpublic java.lang.String getDisplayResult()
throws java.lang.Exception
Document.updateListLabels() method must be called to obtain correct value for the FieldListNum, FieldAutoNum, FieldAutoNumOut and FieldAutoNumLgl fields.java.lang.Exceptionpublic boolean isLocked()
public void isLocked(boolean value)
value - Whether the field is locked (should not recalculate its result).public boolean isDirty()
public void isDirty(boolean value)
value - Whether the current result of the field is no longer correct (stale) due to other modifications made to the document.public FieldFormat getFormat()
FieldFormat object that provides typed access to field's formatting.FieldFormat object that provides typed access to field's formatting.public int getLocaleId()
FieldUpdateCultureSource.FIELD_CODEpublic void setLocaleId(int value)
value - The LCID of the field.FieldUpdateCultureSource.FIELD_CODE