We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Generated Form Fields


I am generating a word document using a mail merge, and inserting certain input text boxes.

This works fine

I then want to load the completed document and read what values were entered into the field, however typing in removes the field, is there any way to have the fields stay in place when data is entered into them?


Thanks for your inquiry. Could you please provide me code that you use to insert formfields during mail merge and attach sample template and output document for testing? I will investigate the problem and provide you more information.

Best regards.

Hi Alexey,

The problem seems to be better in docx, however, once I change everything to docx, the word file it generates is corrupt

Imports Aspose.Words

Imports Aspose.Words.Reporting

Imports System.Data

Imports Aspose.Words.Fields

Imports System.IO

Partial Class _Default

Inherits System.Web.UI.Page

Private mBuilder As DocumentBuilder

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim l As New Aspose.Words.License


Dim doc As Document = New Document("c:\test.docx")

AddHandler doc.MailMerge.MergeField, AddressOf HandleMergeField

Dim baseDT As New DataTable

mBuilder = New DocumentBuilder(doc)

'Dim documentFormFields As FormFieldCollection = doc.Range.FormFields

'Dim formField1 As FormField = documentFormFields(3)




baseDT.Rows.Add(New Object() {1, 1, 1})

baseDT.Rows.Add(New Object() {2, 2, 2})

baseDT.Rows.Add(New Object() {3, 3, 3})

baseDT.TableName = "Base"


doc.Save("Minutes.docx", SaveFormat.Docx, Aspose.Words.SaveType.OpenInBrowser, Response)

End Sub

Private Sub HandleMergeField(ByVal sender As Object, ByVal e As MergeFieldEventArgs)

' We decided that we want all boolean values to be output as check box form fields.

'If TypeOf e.FieldValue Is Boolean Then

' ' Move the "cursor" to the current merge field.

' mBuilder.MoveToMergeField(e.FieldName)

' ' It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.

' Dim checkBoxName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex)

' ' Insert a check box.

' mBuilder.InsertCheckBox(checkBoxName, CBool(e.FieldValue), 0)

' ' Nothing else to do for this field.

' Return

'End If

' Another example, we want the Subject field to come out as text input form field.

Select Case e.FieldName

Case "ID"


mBuilder.InsertTextInput(e.FieldValue & "-" & "1", TextFormFieldType.RegularText, "", " ", 0)

Case "ID2"


mBuilder.InsertTextInput(e.FieldValue & "-" & "2", TextFormFieldType.DateText, "", " ", 0)

Case "ID3"


mBuilder.InsertComboBox(e.FieldValue & "-" & "3", New String() {"One", "Two", "Three"}, 0)

End Select

If e.FieldName = "ID" Then

End If

End Sub

End Class

I found that adding a response.end fixed the problem opening the docs, however the fields still display like in a doc file.

To see the difference, see the attached files

Default.docx was generated, and dot1.docx was created in Word directly


Thank you for additional information. Text Field looks as expected. This is “Text Field (Form Control)” in MS Word. You can try to insert this control using MS Word 2007 then you will get the same result. (You can find this component in “Commands Not in the Ribbon”)

Best regards.

if you look at dot1.docx, it has a text field that when you click on it it enters edit mode, whereas the minutes.docx removes the field

also the drop down on minutes.docx doesn't work where the one on dot1.docx does

Dot1 I created by adding text and date and dropdown fields in word, where minutes.docx was generated

I want to achieve the same effect as in dot1.docx


Thanks for your request. Unfortunately there is no way to insert this kind of fields into the document using Aspose.Words. But if you need enter data only into the form fields you can try to protect document as shown in the following example.

//Create new document and DocumentBuilder

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//Insert few form fields

builder.Write("First Name: ");

builder.InsertTextInput("firstName", TextFormFieldType.RegularText, string.Empty, " ", 0);


builder.Write("Last Name: ");

builder.InsertTextInput("lastName", TextFormFieldType.RegularText, string.Empty, " ", 0);

//Protect document


//Save document


I hope this could help you.

Best regards.