Table of Contents

Method Execute

Namespace
DocWright.MailMerge
Assembly
DocWright.MailMerge.dll

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

document WordDocument

The template, mutated in place.

values IDictionary<string, object>

The record.

options MailMergeOptions

The options, or null for the defaults.

Returns

MergeResult

What the merge did.

Exceptions

ArgumentNullException

document or values is 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

document WordDocument

The template, mutated in place.

data IMergeDataReader

The records.

options MailMergeOptions

The 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

document or data is null.

MergeTemplateException

A region marker is unbalanced or crossed.