Importing MS Word Merge Fields

Starting with TX Text Control .NET 14.0, MS Word Merge Fields can be imported into the TextControl or ServerTextControl with the LoadSettings class. The LoadSettings.ApplicationFieldFormat property is used to enable TX Text Control to load the ApplicationField type text fields.

For MS Word merge fields, it must be set to ApplicationFieldFormat.MSWord.

The LoadSettings.ApplicationFieldTypeNames property sets the type name of each field. For MS Word Merge Fields and Form Fields, it is MERGEFIELD.

The ApplicationField.Parameters property defines the field's parameters, e.g. its functionality.

It has the format MERGEFIELD FieldName [switches]

The following code imports MS Word merge fields from a DOCX file:

[C#]
TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings();
ls.ApplicationFieldFormat = ApplicationFieldFormat.MSWord;
ls.ApplicationFieldTypeNames = new string[] { "MERGEFIELD" };
textControl1.Load(@"C:\test.docx", TXTextControl.StreamType.WordprocessingML, ls);
[Visual Basic]
Dim LS As New TXTextControl.LoadSettings()
LS.ApplicationFieldFormat = ApplicationFieldFormat.MSWord
LS.ApplicationFieldTypeNames = New String() {"MERGEFIELD"}
TextControl1.Load("C:\test.docx", TXTextControl.StreamType.WordprocessingML, LS)

Each MS Word merge field has been imported into the TextControl.ApplicationFields collection after that.

<< Back