2

I am using opentbs to generate reports in .docx format from data entered by users into a form, and would like to be able to add spaces between fields conditionally. Here's the paradigm example of the issue: The user must enter a street address (address1), but the fields immediately before and after the address field (business and address2, respectively) are optional. Is there a way to set up the merge fields in the template so that, if the user puts something into the business field, the document resulting from the merge will have the value of the business field followed by a space, but if the user leaves the field blank, the document resulting from the merge will not have either the field or the space? I can see two possible ways of achieving this: 1. using a stand-alone merge field that prints a space only if the field "business" is not blank; or 2. using a merge field in the template that prints both the value of the field and a space, but only if the field is not blank.

Here's my psuedocode for these two solutions: 1. [onshow.business][onshow;if[business]!=blank;then' ';else''][onshow.address1] 2. [onshow.business AND ' '][onshow.address1]

It seems like this must be possible, and yet I haven't been able to find a way to turn either pseudocode into real, functioning merge fields in my docx. template. I've searched all of the entries on this forum and on the tbs forum, as well as the documentation, but the issue hasn't squarely been raised, and the things I have tried have not worked. Any help would be much appreciated.

4

3 回答 3

4

以防万一有人想要它,这是我最终根据莎拉和 Skrol29 的回答为我的文档整理的内容:

PHP:
没有变化

模板:

[onshow.firstName] [onshow.lastName],[onshow.businessName; if [val] != '; then '     [val],'] [onshow.address1][onshow.address2; if [val] != '' then ' [val]'], [onshow.city], [onshow.state] [onshow.zip]; [onshow.phone]; [onshow.email]

合并 DOCX:businessName 和 address2 留空:

Joe Bloggs, 123 Main Street, Los Angeles, CA 90066; 310-555-1212; test@email.com

填写了businessName,但address2留空:

Joe Bloggs, Smith Co., 123 Main Street, Los Angeles, CA 90066; 310-555-1212; test@email.com

businessName 留空,但 address2 填写:

Joe Bloggs, 123 Main Street Suite 42, Los Angeles, CA 90066; 310-555-1212; test@email.com

既:

Joe Bloggs, Smith Co., 123 Main Street Suite 42, Los Angeles, CA 90066; 310-555-1212; test@email.com
于 2014-03-27T06:44:44.120 回答
4

business如果不是,这将在 的值之后插入一个不间断的空格''

[onshow.business; if [val] != ''; then [val] ]

您可能会遇到的问题是 Word 如何表示空格...我建议先插入一个问题较少的字符以确保您的标签正常工作(如 a ^or 和a可能),然后努力寻找正确的字符/参数组合以使空间工作。

当您开始查看时,我会尝试\shttp ://www.tinybutstrong.com/forum.php?thr=3234 然后我会查看xml:space="preserve"http://www.tinybutstrong.com/forum.php? thr=3263

看起来它显示在这样的<w:t>标签上:<w:t xml:space="preserve">因此您可以尝试以下操作:

PHP:

$f = 'preserve';

模板:

[onshow.business; if [val] != ''; then '[val] ';][onshow.p;att='xml:space']

可能有更好的方法来处理,att但这至少应该让你开始。

于 2014-03-25T15:32:06.813 回答
2

以下两个解决方案假定[onshow.business]并且[onshow.adress1]在同一个 Ms Word 段落中。

你必须:

1) 字段后的空格[onshow.business]与字段的文本格式不同。例如,您可以将空格字符的字体侧增加一。

注意:Word 会根据应用于文本的格式将文本拆分为几个片段。每个片段都在其自己的<w:r>元素中定义。

2)然后在字段上添加参数磁铁[onshow.business],以便在字段为空时删除他的空间。

例子 :

Hello [onload.business;magnet=w:r+w:r] [onload.address1]

|显示片段分隔的相同示例:

Hello |[onload.business;magnet=w:r+w:r]| |[onload.address1]

以汽车为例,该字段[onshow.business]必须与之前的文本位于单独的片段中,否则它将像删除空格一样删除之前的文本。

于 2014-03-25T15:40:32.440 回答