简体   繁体   English

将XML映射窗格与IF域代码Word文档一起使用

[英]Using XML Mapping Pane with IF Field Code Word Document

I have been trying to use the content control from XML Mapping Pane with the IF Field Code. 我一直在尝试将XML映射窗格中的内容控件与IF域代码一起使用。 But I am having some issues. 但是我有一些问题。 It seems that i am not being able to compare the value of the content control with what i want 似乎我无法将内容控件的值与我想要的进行比较

For example: 例如:

{ IF Language_CodeValue <> "DAN" "ENGLISH" "DANISH" } 

Language_CodeValue being a content control from the XML Mapping Pane. Language_CodeValue是XML映射窗格中的内容控件。 Any help would be appreciated. 任何帮助,将不胜感激。 The Language_CodeValue do contain DAN in it when i display it on a word document. 当我在Word文档上显示Language_CodeValue时,它确实包含DAN。 Seems like the comparison with string which is not working 似乎与字符串比较不起作用

Content controls cannot successfully be nested within field codes of any kind. 内容控件无法成功嵌套在任何类型的域代码中。 They don't work correctly. 它们无法正常工作。

When you think about it logically, this makes sense because when a field updates the only thing it can show is the result, which means the content control can't be used. 从逻辑上考虑它是有道理的,因为当字段更新时,它只能显示的结果就是结果,这意味着不能使用内容控件。 Or if it could be used, then the IF field cannot function correctly. 或者,如果可以使用,则IF字段将无法正常运行。 So basically field codes need to ignore content controls. 因此,基本上,域代码需要忽略内容控件。

There's no simple workaround for this, but one possibility would be to use the ContentControlBeforeStoreUpdate event of the Document object to run object model actions when the XML node in the Custom XML Part is changed. 没有简单的解决方法,但是一种可能性是,当更改“定制XML部件”中的XML节点时,使用Document对象的ContentControlBeforeStoreUpdate事件运行对象模型操作。 It can write its content to a CustomDocumentProperty. 它可以将其内容写入CustomDocumentProperty。 A DocProperty field can then be nested in the If field. 然后,可以将DocProperty字段嵌套在If字段中。

Once you've successfully mapped the content control to the custom xml part the ContentControlBeforeStoreUpdate event can be triggered. 成功将内容控件映射到自定义xml部分后,就可以触发ContentControlBeforeStoreUpdate事件。 This event is (must be) defined in the ThisDocument module of the document containing the content control. (必须)在包含内容控件的文档的ThisDocument模块中定义此事件。

In the VBA editor double-click ThisDocument for the document containing the content control in the Project window. 在VBA编辑器中,双击“项目”窗口中包含内容控件的文档的ThisDocument。 From the list at the top left of the code window choose "Document". 从代码窗口左上方的列表中选择“文档”。 From the list at the top right choose ContentControlBeforeStoreUpdate. 从右上角的列表中选择ContentControlBeforeStoreUpdate。 This will insert the Sub...End Sub stubs for the event. 这将为事件插入Sub ... End Sub存根。

Private Sub Document_ContentControlBeforeStoreUpdate( _
            ByVal ContentControl As ContentControl, _
            Content As String)
  Select Case ContentControl.Title
    Case "Tree"
        ActiveDocument.CustomDocumentProperties("test").Value = Content
    Case Else
  End Select
End Sub

Note that all content controls linked to a custom xml part will trigger this event. 请注意,链接到自定义xml部件的所有内容控件都将触发此事件。 You should, therefore, check the title (or tag) property of the content control and branch the appropriate actions. 因此,您应该检查内容控件的title(或标签)属性并分支适当的操作。

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

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