查找欄位屬性
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(); |