Repeating content with Office Open XML

时光怂恿深爱的人放手 提交于 2019-12-06 05:29:47

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.

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 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).

There is no built-in Content Control for repeating content in Word 2007/2010. The following possibilities come to my mind though:

  • Create the full content programmatically using the Open XML SDK. No databinding though.
  • Use Word's MailMerge feature for displaying several similar data sets.
  • Use InfoPath which has better support for repeating content
  • Use a third-party solution such as Windward Reports.

Update: Word 2013 now has a content control for repeating sections.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!