Hide portion of text

Hi,

Quick question. I have a document, where i have several portions, that I want to show based on some code. Is there a way to do this easily?

Right now i have made some tables around the portions and if I want to show that portion, I add a row to the given table. This seems to work fine, but I was wondering if there were a better way?

Hi Danny,
Thanks for your inquiry. If you need to conditionally remove/hide part of content in your document, then maybe you can consider using IF fields. For instance, please see the attached template. If you press Alt+F9 you will see field codes. If condition is true you will see the first text if false the second. Here is a simple code I used for testing:

Document doc = new Document(@"Test001\in.doc");
doc.MailMerge.Execute(new string[]
{
    "test"
}, new object[]
{
    "true"
});
doc.Save(@"Test001\out.doc");

Hope this approach could help you.
Best regards,

Hi,

Thanks for the quick reply. This could possible be a solution to my problem.

But could it be possible to show/hide regions in the document based on some start and end fields?

I would like to do this, because I find it easier to maintain the document later.

Hi
Thanks for your inquiry. Sure, you can use IF fields to show hide regions in MS Word documents. Please follow the link to learn more about IF fields:
https://support.microsoft.com/en-us/office/field-codes-if-field-9f79e82f-e53b-4ff5-9d2c-ae3b22b7eb5e
Best regards,