Visual Studio Tools for Office: Using Visual Basic 2005 with Excel, Word, Outlook, and InfoPath
We can create a similar data-bound document in Word using bookmarks rather than named ranges and a data grid rather than an Excel List object. Create a new Word document project, and again add the Northwind database as a data source to the Data Sources pane. Visual Studio should remember the connection string from last time, so you will not need to configure it again. Unfortunately, in this version of VSTO, there is no way to bind a data table to a Word table, as you can with an Excel list object. Drag the CompanyName as a combo box, the ContactName as a Bookmark, and the entire Products table as a data grid. Use the Products table that is the child of the Suppliers table in the tree view, and you will get a nice master-detail view, as shown in Figure 17.11. Figure 17.11. A data-bound master-detail Word document in the designer.
When you build and run the customized Word document, again, you have a master-detail view of a data table running in Word without writing a single line of code. The running document is shown in Figure 17.12. Figure 17.12. The master-detail view at runtime.
|
Категории