查找字段属性
Contents
[
Hide
]
使用 DocumentBuilder.InsertField 插入的字段返回 Field 对象。这是一个外观类,提供有用的方法来快速查找字段的某些属性。
以下代码示例展示了如何查找字段代码和字段结果:
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-.NET | |
Document doc = new Document(MyDir + "Hyperlinks.docx"); | |
foreach (Field field in doc.Range.Fields) | |
{ | |
string fieldCode = field.GetFieldCode(); | |
string fieldResult = field.Result; | |
} |
请注意,如果您只想查找文档中合并字段的名称,那么您可以使用内置的 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-.NET | |
Document doc = new Document(); | |
string[] fieldNames = doc.MailMerge.GetFieldNames(); |