Find and replace in Docx

Finds and replaces keywords in a docx file.

Find and replace designer

Designer Properties#

  1. Docx File Path The doc file path to find and replace keys.
  2. Key Value Dictionary The Dictionary(string, string) with the keys, and their corresponding values to be replaced in the dictionary.
  3. Output file Path Path to the file that will contain the original document with the keys replaced.

Properties#

Find and replace properties

Document Properties#

See Designer Properties above.

General Properties#

See General Properties.

Misc#

See Misc.

Out Error#

See Out Error.

Result#

  1. Generated File Path to the file that will contain the original document with the keys replaced.
  2. Parse Error The parsing errors reported while processing the docx file.

Tags#

  1. Text End Tag The end tag for the key to be replaced. By default, it is ##.
  2. Text Start Tag The start tag for the key to be replaced. By default, it is ##. For instance, if we want to add a key to be replaced in a docx file using the default values for tags, the key should look like "##key##" where key is the "key" specified in the Key Value Dictionary.

Example#

Find and Replace tokens in docx file

Sample Docx file In this example, we load a sample docx file, look for keys: "first, second" and replace them with test1, test2.

The dictionary with keys and values is specified as:

new Dictionary(of string, string) from
{
{"first", "test1"},
{"second", "test2"}
}

The "key values" dictionary is entered using the expression editor.

Find and replace expression editor

To open the Expression editor just clicking on the "..." button in properties panel for Key Value Dictionary.