locked
Data-bound Word tables RRS feed

  • Question

  • Hi,

    Below my development environment:

    • Windows 7 Professional 64 bits
    • Office 2013 Plus
    • Visual Studio 2013 Professional
    • .NET Framework 4.0
    • Document-level customization for Word

    My goal is to present a table in a document and I need to show all records. I would like to know if it is possible to bind a Word table to a data table. If not, I know I can use data grid views, but data grid views cannot span multiple pages. What is the recommended approach to achieve my goal?

    Carlos

    Monday, December 28, 2015 7:07 AM

Answers

  • Hi Carlos

    It's not possible to bind a Word table in the way you're accustomed. You can

    1. Insert a DATABASE field in the document. Word manages dynamic content through FIELDS. One of these fields is the DATABASE field that sets up a connection to a data source using ODBC or OLE DB.

    You can access this via Insert/Text/Quick Parts/Field. Select Database from the list in the dialog box, then click Insert Database. The Get Data button in the next screen lets you select the data source. Use Query Options to filter/sort and Table AutoFormat to apply formatting. After clicking Insert Data be sure to activate the "Insert as field" checkbox so that you get the dynamic link.

    You can see the field code and edit it by toggling with Alt+F9.

    2. The table can be a set of repeating content controls, which in turn can be mapped to a Custom XML Part in the document. There's no way to have the XML in the Custom XML Part update automatically - you'd have to have code to re-write the underlying XML. But it would be more efficient than using automation to manage a table object in the document...


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    • Marked as answer by Carlos Mallen Tuesday, December 29, 2015 2:53 AM
    Monday, December 28, 2015 5:21 PM