Word 2010结合了INCLUDEPICTURE和IF [英] Word 2010 combining INCLUDEPICTURE and IF

查看:821
本文介绍了Word 2010结合了INCLUDEPICTURE和IF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MS Word 2010我试图将INCLUDEPICTURE字段放入IF语句的块中。虽然IF语句和INCLUDEPICTURE都能正常分离,但它们不能组合使用。

Using MS Word 2010 I am trying to place an INCLUDEPICTURE field into a block of an IF statement. While both the IF statement and the INCLUDEPICTURE work correctly separate, they do not work in combination.

IF语句:

{ IF { MERGEFIELD condition \* MERGEFORMAT } = "expression" "true" "false" \* MERGEFORMAT }

这是正常的。

包含:

{ INCLUDEPICTURE "picture.png" }

这项工作正常也是。

两者的组合:

{ IF { MERGEFIELD condition \* MERGEFORMAT } = "expression" "{ INCLUDEPICTURE "picture.png" }" "false" \* MERGEFORMAT }

这不起作用。如果IF表达式为真,则根本不显示任何内容。

This does not work. If the IF expression is true, nothing is displayed at all.

如何组合IF语句和INCLUDEPICTURE命令?

How can I combine both the IF statement and the INCLUDEPICTURE command?

推荐答案

这是一个众所周知的问题(即你是对的,它不起作用)。

This is a well known-problem (i.e. you are right, it doesn't work).

不幸的是,没有一个特别好的解决方案 - 最简单的方法是使用空白的1像素图像文件。

Unfortunately, there isn't a particularly good solution - the simplest involves using a blank 1-pixel image file.

通常的起点是反转嵌套,以便你有更多这样的东西...

The usual starting point is to invert the nesting so that you have something more like this...

{ INCLUDEPICTURE "{ IF "{ MERGEFIELD condition }" = "expression" "picture.png" }" }" \d }

这总是试图插入图片,并在{MERGEFIELD条件}<>表达式的情况下报告(并插入)错误。最简单的分辨率是有一个空白的1像素图片,你可以包括,例如

This always tries to insert a picture, and will report (and insert) an error in the case where { MERGEFIELD condition } <> "expression". The simplest resolution is to have a blank 1-pixel picture that you can include instead, e.g.

{ INCLUDEPICTURE "{ IF "{ MERGEFIELD condition }" = "expression" "picture.png" "blank1.png" }" }" \d }

删除测试有时更清晰分配并单独进行,特别是如果有多个测试。在这种情况下,

It is sometimes clearer to remove the test and assignment and do it separately, particularly if there are multiple tests. In this case,

{ SET picname "{ IF "{ MERGEFIELD condition }" = "expression" "picture.png" "blank1.png" }" }

或者如果你愿意,

{ IF "{ MERGEFIELD condition }" = "expression" "{ SET picname "picture.png" }" "{ SET picname "blank1.png" }" }

您仍然需要在INNCLUDEPICTURE中嵌套IF才能使其正常工作。您可以使用:

You still need an IF nested inside the INNCLUDEPICTURE to make it work. You can use:

{ INCLUDEPICTURE "{ IF TRUE { picname } }" \d }

如果将这些嵌套字段合并到输出文档,则字段将保留在输出中。如果你想要解析字段(例如,因为你需要将输出发送给没有图像文件的人),那么你需要更像这样的东西:

If you merge those nested fields to an output document, the fields will remain in the output. If you want the fields to be resolved (e.g. because you need to send the output to someone who does not have the image files) then you need something more like this:

{ IF { INCLUDEPICTURE "{ IF TRUE { picname } }" } { INCLUDEPICTURE "{ IF TRUE { picname } }" \d } }

我相信你可以将此减少到

I believe you can reduce this to

{ IF { INCLUDEPICTURE "{ picname }" } { INCLUDEPICTURE "{ IF TRUE { picname } }" \d } }

事实上,我相信你可以插入你知道存在的任何图形文件的完整路径+名称,而不是第一个{picname},例如

In fact, I believe you can insert the full path+name of any graphic file that you know exists instead of the first { picname }, e.g.

{ IF { INCLUDEPICTURE "the full pathname of blank1.png" } { INCLUDEPICTURE "{ IF TRUE { picname } }" \d } }

但你应该检查那些是否适合你。

But you should check that those work for you.

编辑
FWIW,最近的一些测试显示,而图片显示取消链接,保存/重新打开显示重组的链接(在结尾附近有* MERGEFORMATINET),并且图片应该在这些链接中指示的位置。这是否是由于Word的变化我无法分辨。如果有任何变化,它似乎是试图允许Word在.docx内创建的关系记录中进行一些相对路径寻址。

EDIT FWIW, some recent tests suggest that whereas the pictures appear unlinked, a save/re-open displays a reconstituted link (with a *MERGEFORMATINET near the end), and the pictures are expected to be at the locaitons indicated in those links. Whether this is due to a change in Word I cannot tell. If anything has changed, it looks to be an attempt to allow some relative path addressing in the Relationship records that Word creates inside the .docx.

一些观察...


  • 确保路径有双倍的反斜杠,例如
    c:\\mypath \\ blank.png。对于任何路径
    硬编码到字段中,这通常是必需的。对于通过嵌套字段
    代码进入的路径,请检查。

  • 作为一般观点,当文档为a时,使用INCLUDEPICTURE字段
    更容易.doc,而不是.docx,并确保
    文件 - >选项 - >高级 - >常规 - > Web选项 - >文件 - >保存时更新链接
    被选中。否则,Word更有可能替换
    INCLUDEPICTURE字段,结果无法使用Alt-F9重新显示为
    字段

  • 当您想要处理比较时在IF字段中作为字符串,我建议用
    将它们用双引号括起来。
    否则,解析为
    书签名称的{MERGEFIELD}字段可能不会像您希望的那样运行。否则,间距和
    报价主要取决于个人选择。

到目前为止,这些字段结构都不会达成在这种情况下,您可能存在或不存在图片的路径名。如果这是您所需要的,请修改您的原始问题。

So far, none of these field constructions will deal with the situation where you have path names for pictures that may or may not exist. If that is what you need, please modify your original question.

这篇关于Word 2010结合了INCLUDEPICTURE和IF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆