フィールドのプロパティを検索する

Contents
[ ]

DocumentBuilder.InsertField を使用して挿入されたフィールドは Field オブジェクトを返します。これは、フィールドのいくつかのプロパティをすばやく検索するための便利なメソッドを提供するファサード クラスです。

次のコード例は、フィールド コードとフィールド結果を検索する方法を示しています。

// 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 メソッドを使用できることに注意してください。

次のコード例は、ドキュメント内のすべての差し込みフィールドの名前を取得する方法を示しています。

// 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();