API Reference

Class

WordMailMerge

Namespace OfficeIMO.Word
Assembly OfficeIMO.Word
Modifiers static

Provides basic mail merge capabilities by replacing MERGEFIELD fields with supplied values.

Inheritance

  • Object
  • WordMailMerge

Methods

public static Void Execute(WordDocument document, IDictionary<String, String> values, Boolean removeFields = true) #
Returns: Void

Replaces all MERGEFIELD fields in the given document with provided values.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Document to update.
values System.Collections.Generic.IDictionary{System.String,System.String} requiredposition: 1
Dictionary with field names and values.
removeFields System.Boolean = true optionalposition: 2
Determines whether the field codes are removed after replacement.
public static IReadOnlyList<String> ExecuteBatch(String templatePath, IEnumerable<IDictionary<String, String>> records, Func<Int32, IDictionary<String, String>, String> outputPathFactory, Boolean removeFields = true) #
Returns: IReadOnlyList<String>

Creates one merged document per value set from a template file.

Parameters

templatePath System.String requiredposition: 0
Path to the source template document.
records System.Collections.Generic.IEnumerable{System.Collections.Generic.IDictionary{System.String,System.String}} requiredposition: 1
Value sets used to generate output documents.
outputPathFactory System.Func{System.Int32,System.Collections.Generic.IDictionary{System.String,System.String},System.String} requiredposition: 2
Function that returns an output path for each zero-based record index and value set.
removeFields System.Boolean = true optionalposition: 3
Determines whether field codes are removed after replacement.

Returns

Output document paths in generation order.

public static Int32 ExecuteConditionalBlocks(WordDocument document, IDictionary<String, Boolean> conditions, Boolean removeMarkers = true) #
Returns: Int32

Includes or removes conditional template blocks delimited by marker paragraphs such as {{#ShowDiscount}} and {{/ShowDiscount}}.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Document containing conditional marker paragraphs.
conditions System.Collections.Generic.IDictionary{System.String,System.Boolean} requiredposition: 1
Condition values keyed by marker name.
removeMarkers System.Boolean = true optionalposition: 2
When true, matched marker paragraphs are removed from included blocks.

Returns

The number of conditional blocks processed.

public static WordContentControlDataBindingResult ExecuteContentControlDataBindings(WordDocument document, IDictionary<String, String> values, Boolean updateCustomXml = true) #
Returns: WordContentControlDataBindingResult

Fills bound content controls from supplied values and, when possible, updates the backing Custom XML node.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Document containing bound content controls.
values System.Collections.Generic.IDictionary{System.String,System.String} requiredposition: 1
Values keyed by content-control alias, tag, XPath, or storeItemId|XPath.
updateCustomXml System.Boolean = true optionalposition: 2
When true, matching backing Custom XML nodes are updated with supplied values.
public static Int32 ExecuteRepeatingBlockRegions(WordDocument document, IDictionary<String, IEnumerable<WordMailMergeBlockData>> regions, Boolean removeFields = true) #
Returns: Int32

Repeats block-level template regions with nested data, using marker paragraphs such as {{#each Items}} and {{/each Items}}.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Document containing repeated block marker paragraphs.
regions System.Collections.Generic.IDictionary{System.String,System.Collections.Generic.IEnumerable{OfficeIMO.Word.WordMailMergeBlockData}} requiredposition: 1
Repeated region rows keyed by marker name.
removeFields System.Boolean = true optionalposition: 2
Determines whether field codes are removed after replacement.

Returns

The number of generated region instances, including nested instances.

public static Int32 ExecuteRepeatingBlocks(WordDocument document, IDictionary<String, IEnumerable<IDictionary<String, String>>> regions, Boolean removeFields = true) #
Returns: Int32

Repeats block-level template regions delimited by marker paragraphs such as {{#each Items}} and {{/each Items}}.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Document containing repeated block marker paragraphs.
regions System.Collections.Generic.IDictionary{System.String,System.Collections.Generic.IEnumerable{System.Collections.Generic.IDictionary{System.String,System.String}}} requiredposition: 1
Repeated region rows keyed by marker name.
removeFields System.Boolean = true optionalposition: 2
Determines whether field codes are removed after replacement.

Returns

The number of generated region instances.

public static WordMailMergeTableRowGroupResult ExecuteTableRowGroups(WordTable table, Int32 groupTemplateRowIndex, Int32 detailTemplateRowIndex, IEnumerable<WordMailMergeTableRowGroup> groups, Boolean removeFields = true) #
Returns: WordMailMergeTableRowGroupResult

Repeats a group template row and its detail row template for each supplied grouped data set.

Parameters

table OfficeIMO.Word.WordTable requiredposition: 0
Table containing the group and detail template rows.
groupTemplateRowIndex System.Int32 requiredposition: 1
Zero-based row index of the group/header row template.
detailTemplateRowIndex System.Int32 requiredposition: 2
Zero-based row index of the detail row template.
groups System.Collections.Generic.IEnumerable{OfficeIMO.Word.WordMailMergeTableRowGroup} requiredposition: 3
Grouped value sets used to generate group and detail rows.
removeFields System.Boolean = true optionalposition: 4
Determines whether the field codes are removed after replacement.

Returns

Generated group and detail row counts.

public static Int32 ExecuteTableRows(WordTable table, Int32 templateRowIndex, IEnumerable<IDictionary<String, String>> rows, Boolean removeFields = true) #
Returns: Int32

Repeats a table row template once for every supplied value set and applies MERGEFIELD replacements in each generated row.

Parameters

table OfficeIMO.Word.WordTable requiredposition: 0
Table containing the row template.
templateRowIndex System.Int32 requiredposition: 1
Zero-based row index to clone and bind.
rows System.Collections.Generic.IEnumerable{System.Collections.Generic.IDictionary{System.String,System.String}} requiredposition: 2
Value sets used to generate rows.
removeFields System.Boolean = true optionalposition: 3
Determines whether field codes are removed after replacement.

Returns

The number of generated rows.

public static WordMailMergeTemplateInspection InspectTemplate(WordDocument document, IEnumerable<String> mergeFieldNames = null, IEnumerable<String> conditionNames = null, IEnumerable<String> repeatingBlockNames = null) #
Returns: WordMailMergeTemplateInspection

Inspects a Word mail-merge template and optionally validates that merge fields and conditional blocks have supplied values.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Document to inspect.
mergeFieldNames System.Collections.Generic.IEnumerable{System.String} = null optionalposition: 1
Optional supplied MERGEFIELD names. When provided, missing fields are reported as issues.
conditionNames System.Collections.Generic.IEnumerable{System.String} = null optionalposition: 2
Optional supplied conditional block names. When provided, missing conditions are reported as issues.
repeatingBlockNames System.Collections.Generic.IEnumerable{System.String} = null optionalposition: 3
Optional supplied repeated block names. When provided, missing repeated block rows are reported as issues.
public static WordContentControlDataBindingResult RefreshContentControlDataBindings(WordDocument document) #
Returns: WordContentControlDataBindingResult

Updates visible text in bound content controls from their backing Custom XML values.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Document containing bound content controls.
ValidateTemplate 2 overloads
public static WordMailMergeTemplateInspection ValidateTemplate(WordDocument document, IEnumerable<String> mergeFieldNames, IEnumerable<String> conditionNames) #
Returns: WordMailMergeTemplateInspection

Validates a Word mail-merge template against supplied merge-field and conditional-block names.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Document to validate.
mergeFieldNames System.Collections.Generic.IEnumerable{System.String} requiredposition: 1
Supplied MERGEFIELD names.
conditionNames System.Collections.Generic.IEnumerable{System.String} requiredposition: 2
Supplied conditional block names.
public static WordMailMergeTemplateInspection ValidateTemplate(WordDocument document, IEnumerable<String> mergeFieldNames, IEnumerable<String> conditionNames, IEnumerable<String> repeatingBlockNames) #
Returns: WordMailMergeTemplateInspection

Validates a Word mail-merge template against supplied merge-field, conditional-block, and repeated-block names.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Document to validate.
mergeFieldNames System.Collections.Generic.IEnumerable{System.String} requiredposition: 1
Supplied MERGEFIELD names.
conditionNames System.Collections.Generic.IEnumerable{System.String} requiredposition: 2
Supplied conditional block names.
repeatingBlockNames System.Collections.Generic.IEnumerable{System.String} requiredposition: 3
Supplied repeated block names.