Editing text between opening and closing custom tag

Is it possible to remove everything between some kind of a tag?

I would like to delete conditionally everything between opening and closing tag with name (f.e. {{ section1:start }} and {{ section1:end }}).

Hi Patryk,

Thanks for your inquiry. Yes, this is possible. Could you please attach your input Word document (you want to remove content from) and expected Word document showing the final output here for testing. You can create expected Word document using MS Word. We will investigate the structure of your documents and provide you code to achieve this.

Best regards,

Hello Awais,

I would like to achieve something like a dynamic section tag during MailMerge phase. I attached a template (in which I defined two dynamic sections) and a result, which is a outcome of applying (section1 -> true, section2 -> false) to the template.

It doesn’t have to be a MergeField (as in template example) - a simple text marker like {{ SectionStart:section1 }} and {{ SectionEnd:section1 }} will be fine as well (but a solution with MergeField will be cleaner and nicer of course).

Thanks for your help!

Hi Patryk,

Thanks for the additional information. You can achieve this by implementing the following workflow:

  1. Use Document.MailMerge.GetFieldNames method to obtain merge field names in document
  2. Get parent Pargarphs or FieldStart nodes of the first merge field
  3. Get parent Pargarphs or FieldEnd nodes of the second merge field
  4. Extract content enclosed between these start/end nodes. See this article.
  5. Remove the extracted content.

I hope, this helps.

Best regards,