XML mapping with Word & SharePoint

My name is Amani Ahmed and I'm the program manager whose primary focus is programmability,
which are the tools needed to build applications on top of Word (i.e. macros, add-ins, etc)

In the last post, Travis demonstrated the power of Word to transfer data seamlessly back and forth with a SharePoint library. I'll build on that today by showing how to set up a Word document template to accomplish this. Here's a quick video demo of this process, and I've also stepped through it below.

First, let me show you the SharePoint document library we'll be working with. As you can see, we already have three custom columns set up: Buyer, Seller, and Purchase price. These will be the properties we will map within our documents.

Now let's start our new document template for this site. We'll create a very simple contract to use as our base. As you saw in Travis' demo, the text in the template can be very detailed and complex, but for this example, let's keep things easy and just create a title and a place for the buyer name, seller name, and purchase date. We want the document to look nice, so we'll style the text "Contract" as a title using the Quick Styles gallery on the Home tab. We can now save this as a template to the desktop and name it contract.dotx.

Next, we need to drag the template into a directory that can be seen by the SharePoint site. I've already opened the "Forms" directory for our "Demo2" library and can see the default template. We can drop the new contract template in and close this window.

Let's go back to the site and make sure we use the new template instead of the default. We can change this by going back to our document library and then choosing "Settings" --> "Document Library Settings" from the menu. Now, click "Advanced settings" under the "General Settings" heading.

On the next page, we need to change the template URL from "template.doc" to our "contract.dotx" and hit OK at the bottom of the page.

At this point, we can map the properties to our word template. Go back to Advance settings and click "Edit Template" to open the template in Word.

We are now working with the template that is stored on the site, so when we save any changes, it will be that copy that is automatically updated. In order to map the properties we want, we need to add content controls that map to the columns of our site. We do this through "Insert"à"Quick Parts"à"Document Property" on the Ribbon. As you can see, the "buyer" property is in our list so we'll select that for document. The text "[buyer]" will appear in gray text – this is where the mapped property will be inserted in the document. Let's do the same for the other two properties and save our template.

Finally, we can go back to our site to verify our changes by clicking 'OK' and returning to our library main page. From here, let's try making a new document for our library. Click "New" at the top and Word opens up a new document using our template.

Enter in some data…save the document…and we can see the connection between Word and SharePoint that we set up.

Amani Ahmed

Program Manager | Word | Programmability

Office Blogs Comments

Comments: (8) Collapse

  • I'm still examining the issue with the write-protected files in the start folder of Word 2007. I discovered the following which seems like the same issue:

    1) Open the normal.dotm from a location on C: using Word 2007 => it will open without any dialog or write-protection!

    2) Change the user template path in Word's options to a network location and copy your normal.dotm there

    3) Restart Word 2007

    4) Open the normal.dotm from the network location using Word 2007 : You'll get a dialog telling you that normal.dotm is in use by yourself, offering to open it write-protected, open a local copy or get a notification. Why is Word behaving different when the file is on a network location?

  • HELP! Who decided to save the .qat files to the LOCAL SETTINGS folder? This prevents it from roaming with users who use roaming profiles so our users lose their settings every time they log off and back on (terminal server environment). How can we address this?

    Please let us know!

    thanks,

    Wes

    wes@myf.org

  • As an avid Office user, I was severely disappointed when the RTM version of Word 2007 had a button to old WordArt. Yes, old WordArt. Dear God. Why this damn this still here? In B2 and B2TR, I thought it was put there temporarily. But in RTM?! (I downloaded the trial.) What really shocks me is that the new WordArt is implemented. It's in Excel. It's in PowerPoint. But why does Word have old WordArt? (Actually, the new WordArt *is* implemented in Word, but through a loophole. When you create a SmartArt, the SmartArt Tools' 'Format' has new WordArt styles.) Oh, how I wished my computer illiterate friends would finally replace those horrible old WordArt styles in their documents. I seriously hope there's an update for this. (NB. I just don't get it -- it's there; it's there. But then, it's no there. Ran out of time?) (NB2. This e-mail is not a sledge to the Office 2007 suite as a whole. As a whole its revolutionary. I just wonder why this *feature* is absent from *Word*) Cheers, Matthew.

  • This is great for a library of Word documents. But could this be extended to let me pull data from multiple InfoPath forms into a single Word document? I would like to combine information from 40+ status reports submitted to a SharePoint via InfoPath into one Word document with full control over the way the document looks. InfoPath lets me "merge," but I have been unable to get the data formatted the way I need it. So far I haven't had much luck even accessing this data through code. Any suggestions? Thanks! Derek

  • This can be implemented for custom metadata and a few defaults, however 'Version' doesn't seem to be available? Or am I missing something? Surely one of the more important columns that users may wish to include in a document header. How can this be added?? /Andrew

  • I have a SharePoint 2007 library that has certain columns which are configured as a "Choice - Check Box" where in theory the user can select one or multiple options from the list of choices. The theory is to use a Word 2007 document (i.e. table constructed as a form) and include this form as a content type within the SharePoint library. The end-user would use this form to create, review, and even update documents within the library.

    At this point, I can get drop-down lists to intregrate with the Word form by using Quick Parts and selecting the corresponding column from the Document Property selections.

    Problem: I orginally had this library column configured as a "Choice - Checkboxes (allow multiple selections)". However, when I edit the Word form (aka content type), this column option is not included as an available Quick Parts - Document Property option to select and include within the form.

    What have I tried? I have tried re-configuring the library column in SharePoint to use "Radio Buttons" and was able to bring this column into the Word form however rather than radio buttons, the Quick Part was converted to a drop-down list.

    How can I bring this column (configured as "checkboxes") into the Word form? If not a Quick Part, is there another process for doing this?

    Any help is greatly needed!!!

    Thanks

  • Is it me or is the link to the video broken?

    channel9.msdn.com/showscreencast.aspx

    Otherwise great article! This is exacly what I've been looking for. Now if only it was as easy to surface SharePoint versions in Word docs (I really don't like the idea of using Lables via Info Policies).

  • Thanks for the article. I have an extended question. I would like to enter a list of items (buyer, seller, item) in a word document. Where the list length is not predefined. Can i do that with word and sharepoint?

Comments

Comments: (loading) Collapse