Remove Fields
Sometimes it is necessary to remove a field from the document. This may occur when it is to be replaced with a different field type or when the field is no longer needed in the document. For example a TOC
field when saving to HTML.
To remove a field inserted into a document using DocumentBuilder.InsertField, use the returned Field object, which provides a convenient Remove method for easily removing the field from the document.
The following code example shows how to remove a field from the document:
// 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(); |