com.aspose.words
Class FormFieldCollection

java.lang.Object
    extended by com.aspose.words.FormFieldCollection
All Implemented Interfaces:
java.lang.Iterable

public class FormFieldCollection 
extends java.lang.Object

A collection of FormField objects that represent all the form fields in a range.

Example:

Shows how to get a collection of form fields.
Document doc = new Document(getMyDir() + "Form fields.docx");
FormFieldCollection formFields = doc.getRange().getFormFields();

Property Getters/Setters Summary
intgetCount()
           Returns the number of form fields in the collection.
FormFieldget(int index)
           Returns a form field at the specified index.
FormFieldget(java.lang.String bookmarkName)
           Returns a form field by bookmark name.
 
Method Summary
voidclear()
           Removes all form fields from this collection and from the document.
java.util.Iterator<FormField>iterator()
           Returns an enumerator object.
voidremove(java.lang.String formField)
           Removes a form field with the specified name.
voidremoveAt(int index)
           Removes a form field at the specified index.
 

Property Getters/Setters Detail

getCount

public int getCount()
Returns the number of form fields in the collection.

Example:

Shows how insert different kinds of form fields into a document and process them with a visitor implementation.
public void formField() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a combo box
    FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
    comboBox.setCalculateOnExit(true);
    Assert.assertEquals(comboBox.getDropDownItems().getCount(), 3);
    Assert.assertEquals(comboBox.getDropDownSelectedIndex(), 0);
    Assert.assertEquals(comboBox.getEnabled(), true);

    builder.writeln();

    // Use a document builder to insert a check box
    FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
    checkBox.isCheckBoxExactSize(true);
    checkBox.setHelpText("Right click to check this box");
    checkBox.setOwnHelp(true);
    checkBox.setStatusText("Checkbox status text");
    checkBox.setOwnStatus(true);
    Assert.assertEquals(checkBox.getCheckBoxSize(), 50.0d);
    Assert.assertEquals(checkBox.getChecked(), false);
    Assert.assertEquals(checkBox.getDefault(), false);

    builder.writeln();

    // Use a document builder to insert text input form field
    FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Your text goes here", 50);
    Assert.assertEquals(doc.getRange().getFields().getCount(), 3);
    textInput.setEntryMacro("EntryMacro");
    textInput.setExitMacro("ExitMacro");
    textInput.setTextInputDefault("Regular");
    textInput.setTextInputFormat("FIRST CAPITAL");
    textInput.setTextInputValue("This value overrides the one we set during initialization");
    Assert.assertEquals(textInput.getTextInputType(), TextFormFieldType.REGULAR);
    Assert.assertEquals(textInput.getMaxLength(), 50);

    // Get the collection of form fields that has accumulated in our document
    FormFieldCollection formFields = doc.getRange().getFormFields();
    Assert.assertEquals(formFields.getCount(), 3);

    // Iterate over the collection with an enumerator, accepting a visitor with each form field
    FormFieldVisitor formFieldVisitor = new FormFieldVisitor();

    Iterator<FormField> fieldEnumerator = formFields.iterator();
    while (fieldEnumerator.hasNext()) {
        fieldEnumerator.next().accept(formFieldVisitor);
    }

    System.out.println(formFieldVisitor.getText());

    doc.updateFields();
    doc.save(getArtifactsDir() + "Field.FormField.docx");
}

/// <summary>
/// Visitor implementation that prints information about visited form fields.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
    public FormFieldVisitor() {
        mBuilder = new StringBuilder();
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    public int visitFormField(final FormField formField) {
        appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
        appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
        appendLine("\tHelp Text:  " + formField.getHelpText());
        appendLine("\tEntry macro name: " + formField.getEntryMacro());
        appendLine("\tExit macro name: " + formField.getExitMacro());

        switch (formField.getType()) {
            case FieldType.FIELD_FORM_DROP_DOWN:
                appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
                appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
                break;
            case FieldType.FIELD_FORM_CHECK_BOX:
                appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
                appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
                break;
            case FieldType.FIELD_FORM_TEXT_INPUT:
                appendLine("\tInput format: " + formField.getTextInputFormat());
                appendLine("\tCurrent contents: " + formField.getResult());
                break;
        }

        // Let the visitor continue visiting other nodes.
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Adds newline char-terminated text to the current output.
    /// </summary>
    private void appendLine(final String text) {
        mBuilder.append(text + '\n');
    }

    /// <summary>
    /// Gets the plain text of the document that was accumulated by the visitor.
    /// </summary>
    public String getText() {
        return mBuilder.toString();
    }

    private StringBuilder mBuilder;
}

get

public FormField get(int index)
Returns a form field at the specified index.

The index is zero-based.

Negative indexes are allowed and indicate access from the back of the collection. For example -1 means the last item, -2 means the second before last and so on.

If index is greater than or equal to the number of items in the list, this returns a null reference.

If index is negative and its absolute value is greater than the number of items in the list, this returns a null reference.

Parameters:
index - An index into the collection.

Example:

Shows how insert different kinds of form fields into a document and process them with a visitor implementation.
public void formField() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a combo box
    FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
    comboBox.setCalculateOnExit(true);
    Assert.assertEquals(comboBox.getDropDownItems().getCount(), 3);
    Assert.assertEquals(comboBox.getDropDownSelectedIndex(), 0);
    Assert.assertEquals(comboBox.getEnabled(), true);

    builder.writeln();

    // Use a document builder to insert a check box
    FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
    checkBox.isCheckBoxExactSize(true);
    checkBox.setHelpText("Right click to check this box");
    checkBox.setOwnHelp(true);
    checkBox.setStatusText("Checkbox status text");
    checkBox.setOwnStatus(true);
    Assert.assertEquals(checkBox.getCheckBoxSize(), 50.0d);
    Assert.assertEquals(checkBox.getChecked(), false);
    Assert.assertEquals(checkBox.getDefault(), false);

    builder.writeln();

    // Use a document builder to insert text input form field
    FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Your text goes here", 50);
    Assert.assertEquals(doc.getRange().getFields().getCount(), 3);
    textInput.setEntryMacro("EntryMacro");
    textInput.setExitMacro("ExitMacro");
    textInput.setTextInputDefault("Regular");
    textInput.setTextInputFormat("FIRST CAPITAL");
    textInput.setTextInputValue("This value overrides the one we set during initialization");
    Assert.assertEquals(textInput.getTextInputType(), TextFormFieldType.REGULAR);
    Assert.assertEquals(textInput.getMaxLength(), 50);

    // Get the collection of form fields that has accumulated in our document
    FormFieldCollection formFields = doc.getRange().getFormFields();
    Assert.assertEquals(formFields.getCount(), 3);

    // Iterate over the collection with an enumerator, accepting a visitor with each form field
    FormFieldVisitor formFieldVisitor = new FormFieldVisitor();

    Iterator<FormField> fieldEnumerator = formFields.iterator();
    while (fieldEnumerator.hasNext()) {
        fieldEnumerator.next().accept(formFieldVisitor);
    }

    System.out.println(formFieldVisitor.getText());

    doc.updateFields();
    doc.save(getArtifactsDir() + "Field.FormField.docx");
}

/// <summary>
/// Visitor implementation that prints information about visited form fields.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
    public FormFieldVisitor() {
        mBuilder = new StringBuilder();
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    public int visitFormField(final FormField formField) {
        appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
        appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
        appendLine("\tHelp Text:  " + formField.getHelpText());
        appendLine("\tEntry macro name: " + formField.getEntryMacro());
        appendLine("\tExit macro name: " + formField.getExitMacro());

        switch (formField.getType()) {
            case FieldType.FIELD_FORM_DROP_DOWN:
                appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
                appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
                break;
            case FieldType.FIELD_FORM_CHECK_BOX:
                appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
                appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
                break;
            case FieldType.FIELD_FORM_TEXT_INPUT:
                appendLine("\tInput format: " + formField.getTextInputFormat());
                appendLine("\tCurrent contents: " + formField.getResult());
                break;
        }

        // Let the visitor continue visiting other nodes.
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Adds newline char-terminated text to the current output.
    /// </summary>
    private void appendLine(final String text) {
        mBuilder.append(text + '\n');
    }

    /// <summary>
    /// Gets the plain text of the document that was accumulated by the visitor.
    /// </summary>
    public String getText() {
        return mBuilder.toString();
    }

    private StringBuilder mBuilder;
}

get

public FormField get(java.lang.String bookmarkName)
Returns a form field by bookmark name. Returns null if the form field with the specified bookmark name cannot be found.
Parameters:
bookmarkName - Case-insensitive bookmark name.

Example:

Shows how insert different kinds of form fields into a document and process them with a visitor implementation.
public void formField() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a combo box
    FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
    comboBox.setCalculateOnExit(true);
    Assert.assertEquals(comboBox.getDropDownItems().getCount(), 3);
    Assert.assertEquals(comboBox.getDropDownSelectedIndex(), 0);
    Assert.assertEquals(comboBox.getEnabled(), true);

    builder.writeln();

    // Use a document builder to insert a check box
    FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
    checkBox.isCheckBoxExactSize(true);
    checkBox.setHelpText("Right click to check this box");
    checkBox.setOwnHelp(true);
    checkBox.setStatusText("Checkbox status text");
    checkBox.setOwnStatus(true);
    Assert.assertEquals(checkBox.getCheckBoxSize(), 50.0d);
    Assert.assertEquals(checkBox.getChecked(), false);
    Assert.assertEquals(checkBox.getDefault(), false);

    builder.writeln();

    // Use a document builder to insert text input form field
    FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Your text goes here", 50);
    Assert.assertEquals(doc.getRange().getFields().getCount(), 3);
    textInput.setEntryMacro("EntryMacro");
    textInput.setExitMacro("ExitMacro");
    textInput.setTextInputDefault("Regular");
    textInput.setTextInputFormat("FIRST CAPITAL");
    textInput.setTextInputValue("This value overrides the one we set during initialization");
    Assert.assertEquals(textInput.getTextInputType(), TextFormFieldType.REGULAR);
    Assert.assertEquals(textInput.getMaxLength(), 50);

    // Get the collection of form fields that has accumulated in our document
    FormFieldCollection formFields = doc.getRange().getFormFields();
    Assert.assertEquals(formFields.getCount(), 3);

    // Iterate over the collection with an enumerator, accepting a visitor with each form field
    FormFieldVisitor formFieldVisitor = new FormFieldVisitor();

    Iterator<FormField> fieldEnumerator = formFields.iterator();
    while (fieldEnumerator.hasNext()) {
        fieldEnumerator.next().accept(formFieldVisitor);
    }

    System.out.println(formFieldVisitor.getText());

    doc.updateFields();
    doc.save(getArtifactsDir() + "Field.FormField.docx");
}

/// <summary>
/// Visitor implementation that prints information about visited form fields.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
    public FormFieldVisitor() {
        mBuilder = new StringBuilder();
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    public int visitFormField(final FormField formField) {
        appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
        appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
        appendLine("\tHelp Text:  " + formField.getHelpText());
        appendLine("\tEntry macro name: " + formField.getEntryMacro());
        appendLine("\tExit macro name: " + formField.getExitMacro());

        switch (formField.getType()) {
            case FieldType.FIELD_FORM_DROP_DOWN:
                appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
                appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
                break;
            case FieldType.FIELD_FORM_CHECK_BOX:
                appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
                appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
                break;
            case FieldType.FIELD_FORM_TEXT_INPUT:
                appendLine("\tInput format: " + formField.getTextInputFormat());
                appendLine("\tCurrent contents: " + formField.getResult());
                break;
        }

        // Let the visitor continue visiting other nodes.
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Adds newline char-terminated text to the current output.
    /// </summary>
    private void appendLine(final String text) {
        mBuilder.append(text + '\n');
    }

    /// <summary>
    /// Gets the plain text of the document that was accumulated by the visitor.
    /// </summary>
    public String getText() {
        return mBuilder.toString();
    }

    private StringBuilder mBuilder;
}

Method Detail

clear

public void clear()
          throws java.lang.Exception
Removes all form fields from this collection and from the document.

Example:

Shows how insert different kinds of form fields into a document and process them with a visitor implementation.
public void formField() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a combo box
    FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
    comboBox.setCalculateOnExit(true);
    Assert.assertEquals(comboBox.getDropDownItems().getCount(), 3);
    Assert.assertEquals(comboBox.getDropDownSelectedIndex(), 0);
    Assert.assertEquals(comboBox.getEnabled(), true);

    builder.writeln();

    // Use a document builder to insert a check box
    FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
    checkBox.isCheckBoxExactSize(true);
    checkBox.setHelpText("Right click to check this box");
    checkBox.setOwnHelp(true);
    checkBox.setStatusText("Checkbox status text");
    checkBox.setOwnStatus(true);
    Assert.assertEquals(checkBox.getCheckBoxSize(), 50.0d);
    Assert.assertEquals(checkBox.getChecked(), false);
    Assert.assertEquals(checkBox.getDefault(), false);

    builder.writeln();

    // Use a document builder to insert text input form field
    FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Your text goes here", 50);
    Assert.assertEquals(doc.getRange().getFields().getCount(), 3);
    textInput.setEntryMacro("EntryMacro");
    textInput.setExitMacro("ExitMacro");
    textInput.setTextInputDefault("Regular");
    textInput.setTextInputFormat("FIRST CAPITAL");
    textInput.setTextInputValue("This value overrides the one we set during initialization");
    Assert.assertEquals(textInput.getTextInputType(), TextFormFieldType.REGULAR);
    Assert.assertEquals(textInput.getMaxLength(), 50);

    // Get the collection of form fields that has accumulated in our document
    FormFieldCollection formFields = doc.getRange().getFormFields();
    Assert.assertEquals(formFields.getCount(), 3);

    // Iterate over the collection with an enumerator, accepting a visitor with each form field
    FormFieldVisitor formFieldVisitor = new FormFieldVisitor();

    Iterator<FormField> fieldEnumerator = formFields.iterator();
    while (fieldEnumerator.hasNext()) {
        fieldEnumerator.next().accept(formFieldVisitor);
    }

    System.out.println(formFieldVisitor.getText());

    doc.updateFields();
    doc.save(getArtifactsDir() + "Field.FormField.docx");
}

/// <summary>
/// Visitor implementation that prints information about visited form fields.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
    public FormFieldVisitor() {
        mBuilder = new StringBuilder();
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    public int visitFormField(final FormField formField) {
        appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
        appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
        appendLine("\tHelp Text:  " + formField.getHelpText());
        appendLine("\tEntry macro name: " + formField.getEntryMacro());
        appendLine("\tExit macro name: " + formField.getExitMacro());

        switch (formField.getType()) {
            case FieldType.FIELD_FORM_DROP_DOWN:
                appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
                appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
                break;
            case FieldType.FIELD_FORM_CHECK_BOX:
                appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
                appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
                break;
            case FieldType.FIELD_FORM_TEXT_INPUT:
                appendLine("\tInput format: " + formField.getTextInputFormat());
                appendLine("\tCurrent contents: " + formField.getResult());
                break;
        }

        // Let the visitor continue visiting other nodes.
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Adds newline char-terminated text to the current output.
    /// </summary>
    private void appendLine(final String text) {
        mBuilder.append(text + '\n');
    }

    /// <summary>
    /// Gets the plain text of the document that was accumulated by the visitor.
    /// </summary>
    public String getText() {
        return mBuilder.toString();
    }

    private StringBuilder mBuilder;
}

iterator

public java.util.Iterator<FormFielditerator()
Returns an enumerator object.

Example:

Shows how insert different kinds of form fields into a document and process them with a visitor implementation.
public void formField() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a combo box
    FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
    comboBox.setCalculateOnExit(true);
    Assert.assertEquals(comboBox.getDropDownItems().getCount(), 3);
    Assert.assertEquals(comboBox.getDropDownSelectedIndex(), 0);
    Assert.assertEquals(comboBox.getEnabled(), true);

    builder.writeln();

    // Use a document builder to insert a check box
    FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
    checkBox.isCheckBoxExactSize(true);
    checkBox.setHelpText("Right click to check this box");
    checkBox.setOwnHelp(true);
    checkBox.setStatusText("Checkbox status text");
    checkBox.setOwnStatus(true);
    Assert.assertEquals(checkBox.getCheckBoxSize(), 50.0d);
    Assert.assertEquals(checkBox.getChecked(), false);
    Assert.assertEquals(checkBox.getDefault(), false);

    builder.writeln();

    // Use a document builder to insert text input form field
    FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Your text goes here", 50);
    Assert.assertEquals(doc.getRange().getFields().getCount(), 3);
    textInput.setEntryMacro("EntryMacro");
    textInput.setExitMacro("ExitMacro");
    textInput.setTextInputDefault("Regular");
    textInput.setTextInputFormat("FIRST CAPITAL");
    textInput.setTextInputValue("This value overrides the one we set during initialization");
    Assert.assertEquals(textInput.getTextInputType(), TextFormFieldType.REGULAR);
    Assert.assertEquals(textInput.getMaxLength(), 50);

    // Get the collection of form fields that has accumulated in our document
    FormFieldCollection formFields = doc.getRange().getFormFields();
    Assert.assertEquals(formFields.getCount(), 3);

    // Iterate over the collection with an enumerator, accepting a visitor with each form field
    FormFieldVisitor formFieldVisitor = new FormFieldVisitor();

    Iterator<FormField> fieldEnumerator = formFields.iterator();
    while (fieldEnumerator.hasNext()) {
        fieldEnumerator.next().accept(formFieldVisitor);
    }

    System.out.println(formFieldVisitor.getText());

    doc.updateFields();
    doc.save(getArtifactsDir() + "Field.FormField.docx");
}

/// <summary>
/// Visitor implementation that prints information about visited form fields.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
    public FormFieldVisitor() {
        mBuilder = new StringBuilder();
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    public int visitFormField(final FormField formField) {
        appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
        appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
        appendLine("\tHelp Text:  " + formField.getHelpText());
        appendLine("\tEntry macro name: " + formField.getEntryMacro());
        appendLine("\tExit macro name: " + formField.getExitMacro());

        switch (formField.getType()) {
            case FieldType.FIELD_FORM_DROP_DOWN:
                appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
                appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
                break;
            case FieldType.FIELD_FORM_CHECK_BOX:
                appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
                appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
                break;
            case FieldType.FIELD_FORM_TEXT_INPUT:
                appendLine("\tInput format: " + formField.getTextInputFormat());
                appendLine("\tCurrent contents: " + formField.getResult());
                break;
        }

        // Let the visitor continue visiting other nodes.
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Adds newline char-terminated text to the current output.
    /// </summary>
    private void appendLine(final String text) {
        mBuilder.append(text + '\n');
    }

    /// <summary>
    /// Gets the plain text of the document that was accumulated by the visitor.
    /// </summary>
    public String getText() {
        return mBuilder.toString();
    }

    private StringBuilder mBuilder;
}

remove

public void remove(java.lang.String formField)
           throws java.lang.Exception
Removes a form field with the specified name. If there is a bookmark associated with the form field, the bookmark is not removed.
Parameters:
formField - The case-insensitive name of the form field to remove.

Example:

Shows how insert different kinds of form fields into a document and process them with a visitor implementation.
public void formField() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a combo box
    FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
    comboBox.setCalculateOnExit(true);
    Assert.assertEquals(comboBox.getDropDownItems().getCount(), 3);
    Assert.assertEquals(comboBox.getDropDownSelectedIndex(), 0);
    Assert.assertEquals(comboBox.getEnabled(), true);

    builder.writeln();

    // Use a document builder to insert a check box
    FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
    checkBox.isCheckBoxExactSize(true);
    checkBox.setHelpText("Right click to check this box");
    checkBox.setOwnHelp(true);
    checkBox.setStatusText("Checkbox status text");
    checkBox.setOwnStatus(true);
    Assert.assertEquals(checkBox.getCheckBoxSize(), 50.0d);
    Assert.assertEquals(checkBox.getChecked(), false);
    Assert.assertEquals(checkBox.getDefault(), false);

    builder.writeln();

    // Use a document builder to insert text input form field
    FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Your text goes here", 50);
    Assert.assertEquals(doc.getRange().getFields().getCount(), 3);
    textInput.setEntryMacro("EntryMacro");
    textInput.setExitMacro("ExitMacro");
    textInput.setTextInputDefault("Regular");
    textInput.setTextInputFormat("FIRST CAPITAL");
    textInput.setTextInputValue("This value overrides the one we set during initialization");
    Assert.assertEquals(textInput.getTextInputType(), TextFormFieldType.REGULAR);
    Assert.assertEquals(textInput.getMaxLength(), 50);

    // Get the collection of form fields that has accumulated in our document
    FormFieldCollection formFields = doc.getRange().getFormFields();
    Assert.assertEquals(formFields.getCount(), 3);

    // Iterate over the collection with an enumerator, accepting a visitor with each form field
    FormFieldVisitor formFieldVisitor = new FormFieldVisitor();

    Iterator<FormField> fieldEnumerator = formFields.iterator();
    while (fieldEnumerator.hasNext()) {
        fieldEnumerator.next().accept(formFieldVisitor);
    }

    System.out.println(formFieldVisitor.getText());

    doc.updateFields();
    doc.save(getArtifactsDir() + "Field.FormField.docx");
}

/// <summary>
/// Visitor implementation that prints information about visited form fields.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
    public FormFieldVisitor() {
        mBuilder = new StringBuilder();
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    public int visitFormField(final FormField formField) {
        appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
        appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
        appendLine("\tHelp Text:  " + formField.getHelpText());
        appendLine("\tEntry macro name: " + formField.getEntryMacro());
        appendLine("\tExit macro name: " + formField.getExitMacro());

        switch (formField.getType()) {
            case FieldType.FIELD_FORM_DROP_DOWN:
                appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
                appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
                break;
            case FieldType.FIELD_FORM_CHECK_BOX:
                appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
                appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
                break;
            case FieldType.FIELD_FORM_TEXT_INPUT:
                appendLine("\tInput format: " + formField.getTextInputFormat());
                appendLine("\tCurrent contents: " + formField.getResult());
                break;
        }

        // Let the visitor continue visiting other nodes.
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Adds newline char-terminated text to the current output.
    /// </summary>
    private void appendLine(final String text) {
        mBuilder.append(text + '\n');
    }

    /// <summary>
    /// Gets the plain text of the document that was accumulated by the visitor.
    /// </summary>
    public String getText() {
        return mBuilder.toString();
    }

    private StringBuilder mBuilder;
}

removeAt

public void removeAt(int index)
             throws java.lang.Exception
Removes a form field at the specified index. If there is a bookmark associated with the form field, the bookmark is not removed.
Parameters:
index - The zero-based index of the form field to remove.

Example:

Shows how insert different kinds of form fields into a document and process them with a visitor implementation.
public void formField() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a combo box
    FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
    comboBox.setCalculateOnExit(true);
    Assert.assertEquals(comboBox.getDropDownItems().getCount(), 3);
    Assert.assertEquals(comboBox.getDropDownSelectedIndex(), 0);
    Assert.assertEquals(comboBox.getEnabled(), true);

    builder.writeln();

    // Use a document builder to insert a check box
    FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
    checkBox.isCheckBoxExactSize(true);
    checkBox.setHelpText("Right click to check this box");
    checkBox.setOwnHelp(true);
    checkBox.setStatusText("Checkbox status text");
    checkBox.setOwnStatus(true);
    Assert.assertEquals(checkBox.getCheckBoxSize(), 50.0d);
    Assert.assertEquals(checkBox.getChecked(), false);
    Assert.assertEquals(checkBox.getDefault(), false);

    builder.writeln();

    // Use a document builder to insert text input form field
    FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Your text goes here", 50);
    Assert.assertEquals(doc.getRange().getFields().getCount(), 3);
    textInput.setEntryMacro("EntryMacro");
    textInput.setExitMacro("ExitMacro");
    textInput.setTextInputDefault("Regular");
    textInput.setTextInputFormat("FIRST CAPITAL");
    textInput.setTextInputValue("This value overrides the one we set during initialization");
    Assert.assertEquals(textInput.getTextInputType(), TextFormFieldType.REGULAR);
    Assert.assertEquals(textInput.getMaxLength(), 50);

    // Get the collection of form fields that has accumulated in our document
    FormFieldCollection formFields = doc.getRange().getFormFields();
    Assert.assertEquals(formFields.getCount(), 3);

    // Iterate over the collection with an enumerator, accepting a visitor with each form field
    FormFieldVisitor formFieldVisitor = new FormFieldVisitor();

    Iterator<FormField> fieldEnumerator = formFields.iterator();
    while (fieldEnumerator.hasNext()) {
        fieldEnumerator.next().accept(formFieldVisitor);
    }

    System.out.println(formFieldVisitor.getText());

    doc.updateFields();
    doc.save(getArtifactsDir() + "Field.FormField.docx");
}

/// <summary>
/// Visitor implementation that prints information about visited form fields.
/// </summary>
public static class FormFieldVisitor extends DocumentVisitor {
    public FormFieldVisitor() {
        mBuilder = new StringBuilder();
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    public int visitFormField(final FormField formField) {
        appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
        appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
        appendLine("\tHelp Text:  " + formField.getHelpText());
        appendLine("\tEntry macro name: " + formField.getEntryMacro());
        appendLine("\tExit macro name: " + formField.getExitMacro());

        switch (formField.getType()) {
            case FieldType.FIELD_FORM_DROP_DOWN:
                appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
                appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
                break;
            case FieldType.FIELD_FORM_CHECK_BOX:
                appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
                appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
                break;
            case FieldType.FIELD_FORM_TEXT_INPUT:
                appendLine("\tInput format: " + formField.getTextInputFormat());
                appendLine("\tCurrent contents: " + formField.getResult());
                break;
        }

        // Let the visitor continue visiting other nodes.
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Adds newline char-terminated text to the current output.
    /// </summary>
    private void appendLine(final String text) {
        mBuilder.append(text + '\n');
    }

    /// <summary>
    /// Gets the plain text of the document that was accumulated by the visitor.
    /// </summary>
    public String getText() {
        return mBuilder.toString();
    }

    private StringBuilder mBuilder;
}

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.