Merged Documents & Empty Lines

Everything related to our flagship word processor.
Post Reply
Stef
Posts: 31
Joined: 2014-12-28 05:47:24

Merged Documents & Empty Lines

Post by Stef » 2015-09-15 05:43:41

Hello,

When doing a mail merge, some entries will not contain information for all "merge placeholders" and sometimes this will result in an empty line. For example, some addresses require a line for a "PO Box", while others don't:

"First Name" "Surname"
"Institution Name"
"PO Box"
"Address Line 1"
"Address Line 2"
"City"
"Country"

When merging the documents, Nisus does not suppress the empty lines and, instead, just leaves them blank. This means that, before printing your merged document, you have to go through it and delete all the empty lines, which is less than ideal.

Although I hate to mention it, that other word processor makes it easy (or used to make it easy) to suppress the blank lines in the merged document. If I remember correctly, when merging, the programme presented an option: if an entry had no information on a line, you could choose to have it skip the line, or not. Either that or it just deleted blank lines by default.

I'm wondering if there is a way to make Nisus suppress any blank lines in the merged output. I've fiddled around a little, but can't seem to find anything. Any help would be appreciated.

Stef

User avatar
martin
Official Nisus Person
Posts: 4261
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Merged Documents & Empty Lines

Post by martin » 2015-10-07 15:13:24

Stef wrote:when merging, the programme presented an option: if an entry had no information on a line, you could choose to have it skip the line, or not. Either that or it just deleted blank lines by default.
Thanks for the feature request Stef. This sounds like a good option to add, and I'll file your request.
I'm wondering if there is a way to make Nisus suppress any blank lines in the merged output. I've fiddled around a little, but can't seem to find anything.
There is a way to do this, but it takes a little work. The basic idea is to add a mail merge placeholder that uses some Perl code to check if the line should be added or not.

Using a normal merge workflow you might have a template document like this:
placeholder normal.png
placeholder normal.png (27.29 KiB) Viewed 2416 times
If the "Address Line 2" field is empty for a particular address, you'll wind up with an empty line in the merger result. This is the problem you've described.

To solve this problem we'll structure the template document like this instead:
placeholder perl.png
placeholder perl.png (25.28 KiB) Viewed 2416 times
That "Merge Code" placeholder can be inserted via the menu Insert > Merge Placeholder > Other. You'll choose the option for some Perl code:
perl code.png
perl code.png (16.2 KiB) Viewed 2416 times
Here's the text version of the code in the screenshot:

Code: Select all

$line = $record{'Address Line 2'};
if( $line ) {
	print "\n$line";
}
It's nothing fancy. It just checks to see if the address line is empty, and if so, doesn't print anything. If the line isn't empty, then it prints a newline (return) and the line.

I hope that helps. Please let me know if you have any questions. And in case it's helpful, I'll also attach the template and CSV files I used in this very simple example.
docs.zip
(3.54 KiB) Downloaded 96 times

Stef
Posts: 31
Joined: 2014-12-28 05:47:24

Re: Merged Documents & Empty Lines

Post by Stef » 2015-10-09 06:43:08

Thanks indeed, Martin, for your helpful comments and advice. And thanks for filing a request for this feature. An easily accessible option to have Nisus skip empty merge placeholders and, consequently, not include blank lines in merged documents would be a very useful (to my mind, even essential) feature to have.

In the meantime, your pearl-code solution works.

The only inconvenience is formal in nature, in that the template has to be structured a little differently than the desired output. For example, rather than having

«Address Line 1»
«Address Line 2»

you have to have

«Address Line 1» «Merge Code (for Address Line 2)»

In other words, the merge placeholders have to be on the same line rather than on two different lines.

And I'm wondering if this could be avoided so that the layout of the template could be the same as the desired output. For example, concerning the Pearl code you said that:
It just checks to see if the address line is empty, and if so, doesn't print anything. If the line isn't empty, then it prints a newline (return) and the line.
I have no knowledge of Pearl code, and so I'm wondering if it would be possible to add a merge placeholder with some pearl code which would allow the line not to be added in the merged document if it is empty. In other words: if "line not empty", then "include line"; if "line empty", then "skip line". This would allow the template to be structured like the original.

Thanks again!

Stef

User avatar
martin
Official Nisus Person
Posts: 4261
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Merged Documents & Empty Lines

Post by martin » 2015-10-09 13:15:51

Stef wrote:I'm wondering if it would be possible to add a merge placeholder with some pearl code which would allow the line not to be added in the merged document if it is empty. In other words: if "line not empty", then "include line"; if "line empty", then "skip line". This would allow the template to be structured like the original.
Unfortunately that won't be possible Stef. The Perl code used during mail merging can only add content; it cannot remove or skip content. I can understand that this makes composing your template document more awkward– sorry for the trouble.

Stef
Posts: 31
Joined: 2014-12-28 05:47:24

Re: Merged Documents & Empty Lines

Post by Stef » 2015-10-12 11:48:01

Thanks once again, Martin. As mentioned, I have no knowledge of Pearl code, but you've helped make things clear. And, in the meantime, the work-around you suggested is getting the job done.
Your follow-up is appreciated!

macjohnnv
Posts: 2
Joined: 2016-01-12 15:22:17

Re: Merged Documents & Empty Lines

Post by macjohnnv » 2016-01-12 15:31:49

I tried the above code and continue to get the following error:

The following error occurred while attempting to run the merge placeholder's Perl code: Unrecognized character \x{a0}; marked by <--HERE after <--HERE near column1 at (file location).

I am using merge data from a csv file created from numbers. The output looks ok, bu I get the error on every record.

Any suggestions?

User avatar
martin
Official Nisus Person
Posts: 4261
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Merged Documents & Empty Lines

Post by martin » 2016-01-12 17:18:07

macjohnnv wrote:I tried the above code and continue to get the following error:

The following error occurred while attempting to run the merge placeholder's Perl code: Unrecognized character \x{a0}; marked by <--HERE after <--HERE near column1 at (file location).
When you copy the Perl code in Safari it adds non-breaking spaces (U+00A0), which Perl does not tolerate. If you first paste the code into a regular Nisus Writer document and show invisibles, you can replace the non-breaking spaces with regular spaces. I hope that helps, let me know know if you have any more trouble.

macjohnnv
Posts: 2
Joined: 2016-01-12 15:22:17

Re: Merged Documents & Empty Lines

Post by macjohnnv » 2016-01-13 14:41:45

That solved it. Thank you for your help.

Post Reply