API Reference
WordMailMerge
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) #VoidReplaces all MERGEFIELD fields in the given document with provided values.
Parameters
- document OfficeIMO.Word.WordDocument
- Document to update.
- values System.Collections.Generic.IDictionary{System.String,System.String}
- Dictionary with field names and values.
- removeFields System.Boolean = true
- 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) #IReadOnlyList<String>Creates one merged document per value set from a template file.
Parameters
- templatePath System.String
- Path to the source template document.
- records System.Collections.Generic.IEnumerable{System.Collections.Generic.IDictionary{System.String,System.String}}
- Value sets used to generate output documents.
- outputPathFactory System.Func{System.Int32,System.Collections.Generic.IDictionary{System.String,System.String},System.String}
- Function that returns an output path for each zero-based record index and value set.
- removeFields System.Boolean = true
- 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) #Int32Includes or removes conditional template blocks delimited by marker paragraphs such as {{#ShowDiscount}} and {{/ShowDiscount}}.
Parameters
- document OfficeIMO.Word.WordDocument
- Document containing conditional marker paragraphs.
- conditions System.Collections.Generic.IDictionary{System.String,System.Boolean}
- Condition values keyed by marker name.
- removeMarkers System.Boolean = true
- 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) #WordContentControlDataBindingResultFills bound content controls from supplied values and, when possible, updates the backing Custom XML node.
Parameters
- document OfficeIMO.Word.WordDocument
- Document containing bound content controls.
- values System.Collections.Generic.IDictionary{System.String,System.String}
- Values keyed by content-control alias, tag, XPath, or storeItemId|XPath.
- updateCustomXml System.Boolean = true
- 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) #Int32Repeats block-level template regions with nested data, using marker paragraphs such as {{#each Items}} and {{/each Items}}.
Parameters
- document OfficeIMO.Word.WordDocument
- Document containing repeated block marker paragraphs.
- regions System.Collections.Generic.IDictionary{System.String,System.Collections.Generic.IEnumerable{OfficeIMO.Word.WordMailMergeBlockData}}
- Repeated region rows keyed by marker name.
- removeFields System.Boolean = true
- 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) #Int32Repeats block-level template regions delimited by marker paragraphs such as {{#each Items}} and {{/each Items}}.
Parameters
- document OfficeIMO.Word.WordDocument
- 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}}}
- Repeated region rows keyed by marker name.
- removeFields System.Boolean = true
- 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) #WordMailMergeTableRowGroupResultRepeats a group template row and its detail row template for each supplied grouped data set.
Parameters
- table OfficeIMO.Word.WordTable
- Table containing the group and detail template rows.
- groupTemplateRowIndex System.Int32
- Zero-based row index of the group/header row template.
- detailTemplateRowIndex System.Int32
- Zero-based row index of the detail row template.
- groups System.Collections.Generic.IEnumerable{OfficeIMO.Word.WordMailMergeTableRowGroup}
- Grouped value sets used to generate group and detail rows.
- removeFields System.Boolean = true
- 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) #Int32Repeats a table row template once for every supplied value set and applies MERGEFIELD replacements in each generated row.
Parameters
- table OfficeIMO.Word.WordTable
- Table containing the row template.
- templateRowIndex System.Int32
- Zero-based row index to clone and bind.
- rows System.Collections.Generic.IEnumerable{System.Collections.Generic.IDictionary{System.String,System.String}}
- Value sets used to generate rows.
- removeFields System.Boolean = true
- 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) #WordMailMergeTemplateInspectionInspects a Word mail-merge template and optionally validates that merge fields and conditional blocks have supplied values.
Parameters
- document OfficeIMO.Word.WordDocument
- Document to inspect.
- mergeFieldNames System.Collections.Generic.IEnumerable{System.String} = null
- Optional supplied MERGEFIELD names. When provided, missing fields are reported as issues.
- conditionNames System.Collections.Generic.IEnumerable{System.String} = null
- Optional supplied conditional block names. When provided, missing conditions are reported as issues.
- repeatingBlockNames System.Collections.Generic.IEnumerable{System.String} = null
- Optional supplied repeated block names. When provided, missing repeated block rows are reported as issues.
public static WordContentControlDataBindingResult RefreshContentControlDataBindings(WordDocument document) #WordContentControlDataBindingResultUpdates visible text in bound content controls from their backing Custom XML values.
Parameters
- document OfficeIMO.Word.WordDocument
- Document containing bound content controls.
public static WordMailMergeTemplateInspection ValidateTemplate(WordDocument document, IEnumerable<String> mergeFieldNames, IEnumerable<String> conditionNames) #WordMailMergeTemplateInspectionValidates a Word mail-merge template against supplied merge-field and conditional-block names.
Parameters
- document OfficeIMO.Word.WordDocument
- Document to validate.
- mergeFieldNames System.Collections.Generic.IEnumerable{System.String}
- Supplied MERGEFIELD names.
- conditionNames System.Collections.Generic.IEnumerable{System.String}
- Supplied conditional block names.
public static WordMailMergeTemplateInspection ValidateTemplate(WordDocument document, IEnumerable<String> mergeFieldNames, IEnumerable<String> conditionNames, IEnumerable<String> repeatingBlockNames) #WordMailMergeTemplateInspectionValidates a Word mail-merge template against supplied merge-field, conditional-block, and repeated-block names.
Parameters
- document OfficeIMO.Word.WordDocument
- Document to validate.
- mergeFieldNames System.Collections.Generic.IEnumerable{System.String}
- Supplied MERGEFIELD names.
- conditionNames System.Collections.Generic.IEnumerable{System.String}
- Supplied conditional block names.
- repeatingBlockNames System.Collections.Generic.IEnumerable{System.String}
- Supplied repeated block names.
Inherited Methods
public override Boolean Equals(Object obj) #BooleanParameters
- obj Object