Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
A field which is inserted using DocumentBuilder.InsertField returns a Field object. This is a facade class which provides useful methods to quickly find such properties of a field.
The following code example shows how to find the field code and field result:
Note if you are only looking for the names of merge fields in the document then you can instead use the built-in method GetFieldNames.
The following code example shows how to get names of all merge fields in a document.
Q: How can I retrieve the field code of a field in Aspose.Words for Java?
A: After obtaining a Field object (e.g., via DocumentBuilder.insertField or by iterating through the document), call field.getFieldCode(). This method returns the complete field code string, including the field type and its arguments.
Q: How do I get the evaluated result (display text) of a field?
A: Use the field.getResult() method on the Field instance. It returns the current result of the field after evaluation, which is the text that would appear in the document.
Q: How can I list all merge field names in a document?
A: Call document.getMailMerge().getFieldNames(). This method returns a String[] containing the names of every MERGEFIELD present in the document, making it easy to enumerate them.
Q: How can I determine the type of a field (e.g., MERGEFIELD, REF) while iterating?
A: Inspect the field code returned by field.getFieldCode(); the first word indicates the field type. Alternatively, you can use field.getType() which returns a FieldType enum value representing the specific field type.
Q: Can I retrieve field properties from fields located in headers or footers?
A: Yes. Access the header/footer nodes via section.getHeadersFooters(), then iterate their child nodes to locate Field objects. Once you have the Field, getFieldCode() and getResult() work the same way as for body fields.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.