查找欄位屬性

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