删除字段

Contents
[ ]

有时需要从文档中删除字段。 当要用不同的字段类型替换该字段或文档中不再需要该字段时,可能会发生这种情况。 例如保存为HTML时的TOC字段。

使用DocumentBuilder删除插入到文档中的字段。InsertField,使用返回的Field对象,它提供了一个方便的Remove方法,用于轻松地从文档中删除字段。

下面的代码示例演示如何从文档中删除字段:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
Document doc = new Document(getMyDir() + "Various fields.docx");
Field field = doc.getRange().getFields().get(0);
field.remove();