Fill out Form Fields
This guide will show you how to efficiently complete the information in various fields, including text fields, checkboxes, and dropdown menus.
Before you begin
You should get your API key from your UniCloud account.
If this is your first time using UniOffice SDK, follow this guide to set up a local development environment.
Clone the project repository
In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.
git clone https://github.com/unidoc/unioffice-examples
Navigate to the path document/fill-out-form
folder in the unioffice-examples directory.
cd unioffice-examples/document/fill-out-form
How it works
Initially we have the already created form that we are going to use for the example:
Now we are going to proceed to the interaction with the form:
Lines 4-11
import the UniOffice packages and other required dependencies.
The init function in lines 13-20
authenticates your request with your UNIDOC_LICENSE_API_KEY
.
The main function in lines 22-55
demonstrates how the form.docx
document is opened, followed by using the FormFields
function to retrieve all the fields from the file in line 31
. Subsequently, all the fields are iterated through in a loop in lines 34-52
, displaying their characteristics on the screen. Depending on the type of field, whether it’s Text, CheckBox, and/or Dropdown, it’s handled accordingly.
Finally, the file is saved with the changes.
Run the code
Run this command to create a document with the changes made to the different types of fields in the document:
go run main.go
Sample output
found 3 fields
- Name: textBox Type: FormFieldTypeText Value:
- Name: checkbox Type: FormFieldTypeCheckBox Value: false
- Name: comboBox Type: FormFieldTypeDropDown Value: