Insert column break within MailMerge.Execute

Hi there,


I’m trying to force a column break this way, but it is not working.

It seems that it’s not recognizing tag #$NC. How can I accomplish this task?


Document doc = new Document(MyDir + “MailMerge.ExecuteArray.doc”);

doc.MailMerge.Execute(
new string[] {“Code”},
new object[] {“Column1#$NCColumn2”});

doc.Save(Response, “MailMerge.ExecuteArray Out.doc”, ContentDisposition.Inline, null);

Hi Fran,

Thanks for your inquiry. In your case, I suggest you please implement IFieldMergingCallback interface to achieve your requirements. Implement this interface if you
want to control how data is inserted into merge fields during a mail
merge operation. Please see the following highlighted code snippet.

Hope this helps you. Please let us know if you have any more queries.


private class HandleColumnBreak: IFieldMergingCallback

{

void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)

{

if (args.FieldName.Equals("code"))

{

DocumentBuilder builder = new DocumentBuilder(args.Document);

builder.MoveToMergeField(args.FieldName);

builder.InsertBreak(BreakType.ColumnBreak);

args.Text = "";

}

}

/// This is called when mail merge engine encounters Image:XXX merge field in the document.

/// You have a chance to return an Image object, file name or a stream that contains the image.

///

void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)

{

// Do nothing.

}

}

Document doc = new Document(MyDir + "Test02.docx");

doc.MailMerge.FieldMergingCallback = new HandleColumnBreak();

doc.MailMerge.Execute(

new string[] { "Code" },

new object[] { "Column1#$NCColumn2" });

doc.Save(MyDir + "Out.docx");