如何测试字段代码中是否存在 Word 自定义文档属性 (CDP)?
Word 中的以下字段代码显示自定义文档属性“myproperty”(如果存在)的内容;否则不执行任何操作。是否
{IF {DOCPROPERTY "myproperty"} <> "Error! Unknown document property name." {DOCPROPERTY "myproperty"}}
存在的测试基于属性不存在时 Word 返回的错误消息。问题是:此错误消息可以本地化(例如法语等)。
您知道如何以独立于语言环境的方式测试自定义文档属性是否存在吗?这相当于:
{IF {EXIST-DOCPROPERTY "myproperty"}{DOCPROPERTY "myproperty"}}
The following fieldcode in Word displays the contents of the custom document property "myproperty" when it exists; otherwise it does nothing
{IF {DOCPROPERTY "myproperty"} <> "Error! Unknown document property name." {DOCPROPERTY "myproperty"}}
The test for existence is based upon the error message that Word returns if the property does not exist. Trouble is: this error message can be localized (e.g. in French etc).
Do you know how to test for existence of a custom document property in a locale independent manner? This would be equivalent to something like:
{IF {EXIST-DOCPROPERTY "myproperty"}{DOCPROPERTY "myproperty"}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
恕我直言,您偶然发现了 Word 中与语言内容相关的几个问题,并且不存在正确的解决方案。
另一个例子是 {STYLEREF} 字段,它需要对您要引用的样式的引用。虽然您可以在 VAB/VSTO 中通过常量(例如 wdStyleHeading1)引用内置样式,以使其与语言无关,但您必须在该字段中将样式名称添加为英语单词中的“标题 1”。在德语单词中打开文档,您会收到“样式名称未定义”错误,反之亦然,在英语单词中打开德语“STYLEREF“Überschrift 1”}。
您还没有透露整个情况在我的文档模板集中,我通常控制文档,例如,有一个全局加载项运行,我可以通过它控制文档。此外,我发布的模板确实具有自定义功能。文档属性已经定义,因此但是,即使没有定义它们,您也可以在打开文档时创建它们。
IMHO you've stumbled over the few issues in Word which are language-content-related and for which no correct solution exists.
Another example is the {STYLEREF} field, which needs a reference to the style you want to refer to. While you have in VAB/VSTO the possibility to refer to the built-in styles through a constant, e.g. wdStyleHeading1, to be language-independent, with the field you must add the style name as "Heading 1" in an English Word. Open the document in a German Word, and you'll get a "style name not defined" error, and vice versa opening a German "STYLEREF "Überschrift 1"} in an English Word.
You haven't said anything about the whole situation in which you want to address your issue. In my document template sets, I'm normally in control of the documents, e.g. there's a global add-in running through which I can control documents. Additionally, templates issued by me do have the custom document properties already defined, so that errors of your kind can not happen. However, even if they're not defined, you may create them while opening a document.