OpenXML:通过绑定创建可重用的内容控件

发布于 2024-09-12 19:41:33 字数 796 浏览 3 评论 0 原文

我需要将特定的 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月苍老的讽刺 2024-09-19 19:41:33

一个不错的选择是使用 VSTO (Visual Studio for Office)来构建一组附加了预绑定代码的文档模板。这两篇文章为研究此类解决方案提供了一个良好的开端:

有两个线程讨论了一些细节:12

使用 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:

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.

赠我空喜 2024-09-19 19:41:33

这应该是非常简单的。自定义控件不受 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文