Hide empty paragraphs

<< Click to Display Table of Contents >>

Navigation:  Programming > Mail Merge (replace fields with data) and data forms >

Hide empty paragraphs

 

After the mail merge procedure it is possible that some paragraphs are completely empty, except for the remaining fields and maybe space and tab chars.

 

a) Using the function

  DeleteParWithEmptyFields

this paragraphs can be deleted. This function internally uses the function DeleteParWithCondition.

 

The function DeleteParWithCondition works only with paragraphs and tables in the first level (not nested tables). Tables rows which do only contain cells with can be deleted will be deleted as well. If all rows in a table have been deleted that table will be deleted, too.

Inside a table cell all child paragraphs of that cell (if any) are individually checked. If those child paragraphs trigger the 'condition' to true, they will be deleted. If the main cell paragraph trigger the condition to true it will be cleared. The cell will only be deleted if all sibling cells have to be deleted, too. (the complete row)

 

b) You can also temporarily hide paragraphs which do only contain empty fields and spaces.

 

To do so use the event BeforeInitializePar with this code:

 

if par.HasObjects(false,[wpobjMergeField]) and

    not par.IsNonSpace([wpobjMergeField]) then

       include(par.prop, paprHidden)

else  exclude(par.prop, paprHidden);

 

 

c) Delete leading or trailing spaces

 

  function DeleteLeadingSpace(EmptyFieldsToo: Boolean;  InFirstPar : Boolean = TRUE): Boolean;

  function DeleteTrailingSpace(EmptyFieldsToo: Boolean): Boolean;

 

Both functions will stop at the first table they find. They will delete the text (and optionally empty fields) from the start or from the end of the text.