Find Field Properties
Contents
[
Hide
]
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:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
Document doc = new Document(getMyDir() + "Hyperlinks.docx"); | |
for (Field field : doc.getRange().getFields()) | |
{ | |
String fieldCode = field.getFieldCode(); | |
String fieldResult = field.getResult(); | |
} |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
Document doc = new Document(); | |
String[] fieldNames = doc.getMailMerge().getFieldNames(); |