查找字段属性
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-C | |
auto doc = MakeObject<Document>(MyDir + "Hyperlinks.docx"); | |
for(const auto& field : doc->get_Range()->get_Fields()) | |
{ | |
auto fieldCode = field->GetFieldCode(); | |
auto fieldResult = field->get_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-C | |
auto doc = MakeObject<Document>(); | |
ArrayPtr<String> fieldNames = doc->get_MailMerge()->GetFieldNames(); |