我需要将特定的 XML 附加到 Word 文档,以便元素将显示在正确的位置。我可以使用 OpenXML SDK 来完成此操作。
问题是我也希望能够定义已经绑定在某种模板中的内容控件,以便其他人可以创建 xml 将附加到的真实文档模板。好吧,不确定人们会理解我的意思,所以我会进一步解释。
可能有许多不同的文档模板将使用相同的 XML 数据以及相同的内容控件。由其他人来创建该文档。
场景:由于某些更改(新布局或某些内容),一些不是程序员的人需要为常用信息创建一个新表单。这与 XML 信息无关,保持不变。
“某个家伙”的最佳解决方案是在 Word 中创建文档并将内容控件拖动到位(或类似的解决方案)。然后,当 XML 添加到文档中时,就不会出现问题了,因为内容控件已预先绑定。
现在这里有几点:
1)内容控件可以预绑定吗?如果路径中没有 XML,它不会就保持空而没有问题吗?
2) 由于 i4i 诉讼,像这样将内容控件绑定到 CustomXML 在 Word 的未来版本中是否仍然有效?
3)是否还有比这个更好的最佳解决方案?
提前致谢。
编辑:
更清楚。我不想创建具有一些名称来标识它们和数据绑定 xpath 的内容控件。然而此时,路上什么也没有。
另一个用户进来并创建一个表单,决定布局等,然后将内容控件添加到他想要信息的位置。
随后,使用新表格请求项目 X 的信息。因此,将获取该表单的副本,并将 CustomXML 添加到 Docx 文件中。现在,由于 XML 模式是预先已知的,并且在决定 CC 的路径时使用,因此该 XML 数据将绑定到内容控件。
I need to attach specific XML to a word document so the elements will show up in the right places. This I can do with OpenXML SDK.
The thing is I want too be able to define the Content Controls already bounded in some sort of template so other people can create the real document template the xml will be attached to. Ok not sure people will undestand what I mean so I will explain further.
There may be many different document templates that will use the same XML data and so the same Content Controls. It's up to someone else to create the document.
Scenario: Some dude that's not a programmer needs to create a new form for the usual info because of some changes ( new layout or somehting ). This has nothing to do with the XML info, that stays the same.
Optimal solution for "some dude" would be to create the document in Word and drag the Content Controls into place ( or some solution similiar). Then when the XML gets added to the document there is no problem as the Content Controls are pre-binded.
Now there are a few points here:
1) Can Content Controls be pre-binded? If there is no XML at the path won't it just stay empty without problems?
2) Will binding Content Controls to CustomXML's like this still work in future versions of Word because of the i4i lawsuit?
3) Is there perhaps another optimal solution better then this?
Thanks in advance.
EDIT:
To be more clear. I wan't to create Content Controls that would have some name to identify them and a databound xpath. However at that moment there is nothing at the path.
Another user comes in and creates a form, decides the layout on so on, and then adds the Content Controls into the places he wants the info to be.
Later on the info for item X is requested using the new form. So a copy of that form will be taken and the CustomXML will be added into the Docx file. Now because the XML shchema was known beforehand and used when deciding the paths for the CC's this XML data will be bound to the Content Controls.
发布评论
评论(2)
一个不错的选择是使用 VSTO (Visual Studio for Office)来构建一组附加了预绑定代码的文档模板。这两篇文章为研究此类解决方案提供了一个良好的开端:
控件
XML 部分
有两个线程讨论了一些细节:1 和 2。
使用 VSTO 的好处之一是您可以挂钩 内容控制事件:Word 2007 中的内容控制事件模型。
如果 VSTO 不是一个选项,您可以随时查看 在不启动 Microsoft Office 的情况下将自定义 XML 部分添加到文档。
One great option would be to use VSTO (Visual Studio for Office) to build a set of document templates that have your prebinding code attached. These two articles provide a good start into looking into this type of a solution:
Controls
XML Parts
There are two threads that discuss some details of this: 1 and 2.
One of the benefits about using VSTO is that you can hook the Content Control events: Content Control Event Model in Word 2007.
If VSTO is not an option, you can always look at Add Custom XML Parts to Documents Without Starting Microsoft Office.
这应该是非常简单的。自定义控件不受 i4i 诉讼的影响,您可以使用每个控件中的 tag 属性来命名它们(警告 - 限制为 64 个字符)。
This should be very straightforward. Custom controls are not impacted by the i4i lawsuit and you can name them using the tag property in each control (warning - it is limited to 64 characters).