Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created November 7, 2022 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/7ac47780f8422e82078373d74ce29faa to your computer and use it in GitHub Desktop.
Save bjoerntx/7ac47780f8422e82078373d74ce29faa to your computer and use it in GitHub Desktop.
private void Mm_FieldMerged(object sender, MailMerge.FieldMergedEventArgs e) {
var keyword = "%REMOVELAST%:";
// return if field is outside block
if (e.MergeBlockName == "" || e.MailMergeFieldAdapter.TypeName != "MERGEFIELD")
return;
// convert to the MergeField
MergeField field = ((MergeField)e.MailMergeFieldAdapter);
// if "text after" contains keyword
if (field.TextAfter.StartsWith(keyword)) {
if (bLastBlockRow == true) { // remove "text after" when last row
field.TextAfter = "";
}
else { // else keep "text after" string
field.TextAfter = field.TextAfter.Substring(
keyword.Length,
field.TextAfter.Length - keyword.Length);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment