查找字段属性
Contents
[
Hide
]
使用DocumentBuilder插入的字段。InsertField返回Field对象。 这是一个facade类,它提供了快速查找字段的此类属性的有用方法。
下面的代码示例演示如何查找字段代码和字段结果:
This file contains 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(); | |
} |
注意如果您只是在文档中查找合并字段的名称,那么您可以改为使用内置方法GetFieldNames。
下面的代码示例演示如何获取文档中所有合并字段的名称。
This file contains 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(); |