Working with Form Fields
A document that contains fill-in blanks (fields) is known as a form. For example, you can create a registration form in Microsoft Word that uses drop-down lists from which users can select entries. The Form
field is a location where a particular type of data, such as a name or address, is stored. Form fields in Microsoft Word include text input, combobox and checkbox.
You can use form fields in your project to “communicate” with your users. For example, you create a document whose content is protected, but only form fields are editable. The users can enter the data in the form fields and submit the document. Your application that uses Aspose.Words can retrieve data from the form fields and process it.
Placing form fields into the document via code is easy. DocumentBuilder has special methods for inserting them, one for each form field type. Each of the methods accepts a string parameter representing the name of the form field. The name can be an empty string. If however you specify a name for the form field, then a bookmark is automatically created with the same name.
Insert Form Fields
Form fields are a particular case of Word fields that allows “interaction” with the user. Form fields in Microsoft Word include textbox, combo box and checkbox.
DocumentBuilder provides special methods to insert each type of form field into the document: insertTextInput, insertCheckBox or insertComboBox.
The following code example shows how to insert a combobox form field into a document:
Insert a Text Input
Use the insertTextInput method to insert a textbox into the document.
The following code example shows how to insert a text input form field into a document:
Insert a Check Box
Call insertCheckBox to insert a checkbox into the document.
The following code example shows how to insert a checkbox form field into a document:
Insert a Combo Box
Call insertComboBox to insert a combobox into the document.
The following code example shows how to insert a Combobox form field into a document:
Obtain Form Fields
A collection of form fields is represented by the FormFieldCollection class that can be retrieved using the Range.getFormFields property. This means that you can obtain form fields contained in any document node including the document itself.
The following code example shows how to get a collection of form fields:
You can get a particular form field by its index or name.
The following code example shows how to access form fields:
The FormField properties allow you to work with form field name, type, and result.
The following code example shows how to work with form field name, type, and result: