Shirish Pulikkal

I need to implement the following functionality in Word 2007:

I have created a ContentControl in a Word document. Also I have a button on the Ribbon Control. When I click on the button, the ContentControl needs to be replaced by a Word Table. The data for table would come from database.

Another functionality which is required is the ability to right click the content control and choose the columns to be displayed for the table using a context menu.

So far I have seen content controls being bound to a single node using CustomXMLPart. However I haven't found anything which shows how to bind it to a collection of nodes.

So I have 2 questions.

1. Can content controls be bound to a collection of nodes If not what is the best way of replacing a placeholder in Word with a table.

2. Can custom ContextMenus be attached to content controls

Any sample code or pointer in the right direction will be very much appreciated.

Thanks,

Shirish Pulikkal




Re: Visual Studio Tools for Office Can ContentControls be bound to a collection of Nodes?

Shirish Pulikkal

I 'm planning on using WordProcessingML to generate word tables using data from database.

If there is a better way to do this, just shoot..

Best,

Shirish






Re: Visual Studio Tools for Office Can ContentControls be bound to a collection of Nodes?

Cindy Meister

Shirish Pulikkal wrote:

1. Can content controls be bound to a collection of nodes If not what is the best way of replacing a placeholder in Word with a table.

No... (more below)

Shirish Pulikkal wrote:

2. Can custom ContextMenus be attached to content controls

Not directly. But you could create a context menu (Popup type of CommandBar (the only kind Office 2007 still supports) and display it when the user right-clicks on the range. Look up the older documentation on CommandBars and hooking into the WindowBeforeRightClick event. For example

http://msdn2.microsoft.com/en-us/library/scff9c7c(VS.80).aspx
http://support.microsoft.com/kb/209140/en-us

Back to data-binding and tables...

The Word 2007 object model doesn't provide any complex data-binding scenarios for content controls. Basically, you currently have to "roll your own". No telling what the "Orcas" version of VSTO may bring in that regard.

The most efficient method I know to create/extract tables of data in Word is to use a character-delimited format. You can use pretty much anything for the character delimiter; the record delimiter must be a carriage return (Ascii 13). If your data may contain this character, then you need to replace it with another character, then replace it again after converting the delimited text to a table. See this article for details http://msdn2.microsoft.com/en-us/library/aa537149(office.11).aspx

Or, you could build the table in WordProcessingML then dump it in using the InsertXML method.

If you want data-binding, then the best you can do is to link to an external table. Probably be a Database field with an ODBC connection (also mentioned in the article).






Re: Visual Studio Tools for Office Can ContentControls be bound to a collection of Nodes?

Shirish Pulikkal

Cindy,

Thanks for your reply. Your comments were extremely helpful!

Shirish