使用 Office Open XML 重复内容
我一直在研究 Office Open XML 文档规范的可能性。我对能够将自定义 XML 内容添加到文档并将其绑定到内容控件特别感兴趣。我想知道是否可以有重复的内容控制类型?
例如,假设我的 .docx 文件中有一些自定义 XML,如下所示:
<Work>
.
.
<People>
<Person>
<Name>Jane Doe</Name>
<EmailAddress>[email protected]</EmailAddress>
</Person>
<Person>
<Name>John Doe</Name>
<EmailAddress>[email protected]</EmailAddress>
</Person>
</People>
</Work>
是否有任何重复内容控件(类似于 ASP 转发器),我可以使用它来生成类似于
- Jane Doe 的输出 ([电子邮件受保护])
- John Doe ([email protected])
如果没有类型的控件,我想我可以对word文档本身进行一些处理以生成一个列表。有没有人这样做过并有一些有用的指示?
I've been checking out what is possible with the Office Open XML specification for documents. I'm particularly interested in being able to add custom XML content to a document and binding it to content controls. I was wondering if it is possible to have a repeating content control type?
For example, say I have some custom XML in my .docx file that looks like so:
<Work>
.
.
<People>
<Person>
<Name>Jane Doe</Name>
<EmailAddress>[email protected]</EmailAddress>
</Person>
<Person>
<Name>John Doe</Name>
<EmailAddress>[email protected]</EmailAddress>
</Person>
</People>
</Work>
Is there any repeating content control (similar to an ASP repeater) that I could use to generate output that looks something like
- Jane Doe ([email protected])
- John Doe ([email protected])
If there are no types of controls, I guess I could do some processing on the word document itself to generate a list. Has anyone done this and have some helpful pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 0xA3 所说,没有这样的内置内容,它将由 WordprocessingML 操作。但以下是从数据库中提取数据以创建多个条目的示例: 将数据从数据库推送到 Word 文档。
另外,关于一般数据绑定主题,这里有一个很好的入门教程:将 Word 2007 内容控件链接到自定义 XML。
As 0xA3 says, there is nothing built-in like this, it would be WordprocessingML-manipulated. But here is an example of pulling data from a database to create multiple entries: Pushing Data from a Database into a Word Document.
Also, on the subject of databinding in general, here is a good starter tutorial: Linking Word 2007 Content Controls to Custom XML.
Word 2013 对内容控件进行了一些改进。包括重复内容控制。我还没有测试过。
http://msdn.microsoft.com/en-us/library /office/jj889465.aspx#WordCC_RepeatingSection
对于 Word 2007 和 2010,您必须执行一些额外处理来创建具有内容控制的行,并将它们与生成的 Xpath 查询绑定。您可以查看以下视频。
With Word 2013, there are some improvement for content controls. Including a repeating content control. I haven't test it.
http://msdn.microsoft.com/en-us/library/office/jj889465.aspx#WordCC_RepeatingSection
With Word 2007 and 2010, you have to do some extraprocessing for creating rows with content control and bind them with generated Xpath query. You can check the following video.
http://www.microsoft.com/uk/msdn/screencasts/screencast/261/Office-Open-XML-Content-Controls-and-Repeating-Data-Part-1-of-3.aspx
http://dev.plutext.org/svn /docx4j/trunk/docx4j/sample-docs/databinding/conventions.html 提出了执行此操作的约定。您确实需要预处理 docx 来克隆内容控件 n 次;目前有代码可以通过 Word 宏或 Java (docx4j) 来执行此操作。
http://dev.plutext.org/svn/docx4j/trunk/docx4j/sample-docs/databinding/conventions.html proposes a convention for doing this. You do need to pre-process the docx to clone the content control n times; currently there is code for doing this via a Word macro, or in Java (docx4j).
Word 2007/2010 中没有用于重复内容的内置内容控件。但我想到了以下可能性:
更新:Word 2013 现在具有用于重复部分的内容控件。
There is no built-in Content Control for repeating content in Word 2007/2010. The following possibilities come to my mind though:
Update: Word 2013 now has a content control for repeating sections.