I would like to leave the mergeField fields blank in the document but remove the TableStart / TableEnd tags. Just like in the picture below. How can I do it? I used the “doc.MailMerge.CleanupOptions” option but it removes entire Tablestart / TableEnd regions from me
@damiankienczkowski,
To remove a field from your document, please use the Field.Remove() method. For example, if you need to remove the first field from your document, you can use the following code:
Field field = doc.Range.Fields[0];
field.Remove();
For more information please see the following article:
The following code deletes all the merge fields, that contain “TableStart” or “TableEnd” in their tag. You can use it in your case.
foreach (FieldStart fieldStart in doc.GetChildNodes(NodeType.FieldStart, true))
{
var fieldCode = fieldStart.GetField().GetFieldCode();
if (fieldStart.FieldType.Equals(FieldType.FieldMergeField) && (fieldCode.Contains("TableStart") || (fieldCode.Contains("TableEnd"))))
fieldStart.GetField().Remove();
}