删除字段
Contents
[
Hide
]
有时需要从文档中删除字段。当需要用不同的字段类型替换该字段或文档中不再需要该字段时,可能会发生这种情况。例如保存为 HTML 时的 TOC
字段。
要删除使用 DocumentBuilder.InsertField 插入到文档中的字段,请使用返回的 Field 对象,该对象提供了方便的 Remove 方法,可以轻松地从文档中删除字段。
以下代码示例展示了如何从文档中删除字段:
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 + "Various fields.docx"); | |
Field field = doc.Range.Fields[0]; | |
field.Remove(); |
您可以从 Aspose.Words GitHub 下载本示例的示例文件。