简体   繁体   English

MERGEFIELD 的 MS Word MAILMERGE 自动编号

[英]MS Word MAILMERGE autonumbering for MERGEFIELD

I just learn how to use MAILMERGE in MS Word.我刚刚学习了如何在 MS Word 中使用 MAILMERGE。 I want to list my MERGEFIELD use alphabetic sequence and my code is like this :我想列出我的 MERGEFIELD 使用字母顺序,我的代码是这样的:

{ SEQ list \* alphabetic }. { MERGEFIELD item1 }
{ SEQ list \* alphabetic }. { MERGEFIELD item2 }
{ SEQ list \* alphabetic }. { MERGEFIELD item3 }
{ SEQ list \* alphabetic }. { MERGEFIELD item4 }
{ SEQ list \* alphabetic }. { MERGEFIELD item5 }

And the result from code above is :上面代码的结果是:

a.  duck
b.  dog
c.  bird
d.  cat
e.  pig

I have problem when one or more MERGEFIELD value is empty.当一个或多个 MERGEFIELD 值为空时,我会遇到问题。 For example if { MERGEFIELD item3 } is empty and it will produce list like this :例如,如果 { MERGEFIELD item3 } 为空,它将生成如下列表:

a.  duck
b.  dog
c.  
d.  cat
e.  pig

What I want is like this :我想要的是这样的:

a.  duck
b.  dog
c.  car
d.  pig

If it is Windows Word 2003 or later (or possibly Word XP, I forget), the simplest approach is probably to use the following nested field codes and rely on Word to "suppress blank lines" (which is its default setting)如果是Windows Word 2003 或更高版本(或者可能是 Word XP,我忘记了),最简单的方法可能是使用以下嵌套域代码并依靠 Word 来“抑制空行”(这是其默认设置)

{ MERGEFIELD item1 \b "{ SEQ { IF { MERGEFIELD item1 } = "" nolist list } \*alphabetic }. " }
{ MERGEFIELD item2 \b "{ SEQ { IF { MERGEFIELD item2 } = "" nolist list } \*alphabetic }. " }
{ MERGEFIELD item3 \b "{ SEQ { IF { MERGEFIELD item3 } = "" nolist list } \*alphabetic }. " }
{ MERGEFIELD item4 \b "{ SEQ { IF { MERGEFIELD item4 } = "" nolist list } \*alphabetic }. " }
{ MERGEFIELD item5 \b "{ SEQ { IF { MERGEFIELD item5 } = "" nolist list } \*alphabetic }. " }

(All the { } have to be the special field code brace pairs that you can insert in Windows Word using ctrl-F9. Also, when you preview, the empty lines will still appear to be present, with a ".." at the beginning, but they should disappear when you actually perform the merge.) (所有 { } 必须是您可以使用 ctrl-F9 在 Windows Word 中插入的特殊字段代码大括号对。此外,当您预览时,空行仍会出现,并带有“..”开始,但当您实际执行合并时它们应该消失。)

If you are using Windows Word XP/2000 or earlier, or any version of Mac Word, the \\b flag is not supported.如果您使用的是 Windows Word XP/2000 或更早版本,或任何版本的 Mac Word,则不支持 \\b 标志。 So you have to use IF fields to generate the results for the blank/non-blank cases.因此,您必须使用 IF 字段来生成空白/非空白案例的结果。 The problem is that SE fields inside IF fields are generally evaluated whether or not the resulting text is output, so you end up with gaps in the sequence.问题是 IF 字段内的 SE 字段通常会评估是否输出结果文本,因此您最终会在序列中出现间隙。 Even trying to get Word to use two different sequences ("list" and "nolist" as above) does not work as you might hope.即使试图让 Word 使用两个不同的序列(如上的“list”和“nolist”)也无法如您所愿。 However, there is another approach you can try (it should work with all versions of Word):但是,您可以尝试另一种方法(它应该适用于所有版本的 Word):

{ IF { MERGEFIELD item1 } <> "" "{ SET list { =list+1 } }{ list \*alphabetic }. { MERGEFIELD item1 }
" }{ IF { MERGEFIELD item2 } <> "" "{ SET list { =list+1 } }{ list \*alphabetic }. { MERGEFIELD item2 }
" }{ IF { MERGEFIELD item3 } <> "" "{ SET list { =list+1 } }{ list \*alphabetic }. { MERGEFIELD item3 }
" }{ IF { MERGEFIELD item4 } <> "" "{ SET list { =list+1 } }{ list \*alphabetic }. { MERGEFIELD item4 }
" }{ IF { MERGEFIELD item5 } <> "" "{ SET list { =list+1 } }{ list \*alphabetic }. { MERGEFIELD item5 }
" }

Notice that in this case we cannot rely on Word to suppress the blank lines resulting from an empty IF field result, so instead we put a paragraph mark at the end of the text that the IF field inserts when the MERGEFIELD result is not blank.请注意,在这种情况下,我们不能依靠 Word 来抑制由空 IF 字段结果产生的空行,因此我们在 MERGEFIELD 结果不是空白时在 IF 字段插入的文本末尾放置了一个段落标记。

Either approach should extend up to as many items as you need, but be aware that the "letter sequence" produced by *alphabetic is not任何一种方法都应该扩展到您需要的尽可能多的项目,但请注意 *alphabetic 产生的“字母序列”不是

ab . AB . . . z aa ab . z aa ab 。 . . az ba bb .啊啊啊啊啊啊啊啊. . bz bz

as you might expect, but正如你所料,但是

ab . AB . . . z aa bb . z aa bb 。 . . zz aaa bbb . zz aaa bbb 。 . . zzz

. .

If you actually want the first, more familiar, sequence, you will need to do more.如果你真的想要第一个更熟悉的序列,你需要做更多的事情。 (I have done this before but may re-research it). (我以前做过这个,但可能会重新研究它)。

However, if you want to make it easier to extend the item count, if the fields continue to be numbered as item6, item7 etc., you can modify the field coding so that all you need to do is paste in the number of copies you need.但是,如果您想更轻松地扩展项目计数,如果字段继续编号为 item6、item7 等,您可以修改字段编码,以便您只需粘贴您的副本数需要。 For the coding that uses SEQ, you could use对于使用 SEQ 的编码,您可以使用

{ MERGEFIELD "item{ SEQ i }" \b "{ SEQ { IF MERGEFIELD "item{ SEQ i \c }" } = "" nolist list } \*alphabetic }. " }

For the coding that uses SET, you could use对于使用 SET 的编码,您可以使用

{ IF { MERGEFIELD "item{ SEQ i}" } <> "" "{ SET list { =list+1 } }{ list \*alphabetic }. { MERGEFIELD "item{ SEQ i \c }" }
" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM