GemBox Support Forum

Default text if range is empty

Hi, I have a pretty clean merge process flowing but now being asked to conditionally put text in the document if no records are available to merge. Any examples or recommended approach?

Before invoking document.MailMerge.Execute() I’m setting ClearOptions with RemoveEmptyRanges – is there maybe a way to, for example, get a RemovingEmptyRange event and then write content into the document to replace?

Hi Matthew,

I think the easiest way would be to just add an IF field with the desired default text.

For example, something like this:

{ IF { MERGEFIELD IsMyRangeEmpty } = True "My default text." "" }

You could create that IsMyRangeEmpty property in your data source so that it depends on the range’s data.

I hope this helps.