Method Execute
Execute(WordDocument, IDictionary<string, object?>, MailMergeOptions?)
Merges one record into the document in place.
public static MergeResult Execute(this WordDocument document, IDictionary<string, object?> values, MailMergeOptions? options = null)
Parameters
documentWordDocumentThe template, mutated in place.
valuesIDictionary<string, object>The record.
optionsMailMergeOptionsThe options, or null for the defaults.
Returns
- MergeResult
What the merge did.
Exceptions
- ArgumentNullException
documentorvaluesis null.- MergeTemplateException
A region marker is unbalanced or crossed.
Execute(WordDocument, IMergeDataReader, MailMergeOptions?)
Merges records into the document in place.
public static MergeResult Execute(this WordDocument document, IMergeDataReader data, MailMergeOptions? options = null)
Parameters
documentWordDocumentThe template, mutated in place.
dataIMergeDataReaderThe records.
optionsMailMergeOptionsThe options, or null for the defaults.
Returns
- MergeResult
What the merge did.
Remarks
The document is produced by walking a record cursor: a copy of the template is emitted
per record, separated according to RecordSeparator, and a
copy consumes more than one record when it contains NEXT or NEXTIF --
which is how a sheet of labels puts a different record in each cell.
Records are pulled one at a time, so the source side stays bounded however many there are. The produced document necessarily grows, which is what MaxRecords bounds.
Exceptions
- ArgumentNullException
documentordatais null.- MergeTemplateException
A region marker is unbalanced or crossed.