If you have already installed some apps from the Store on office.com into your Office 2013 clients, then you will have noticed that the app for Office only interacts with the document at the point where the user has placed the insertion point in the document, or has selected text, etc. Essentially, the app requires user actions for the app to interact with the document. This is great for apps where you want the user to be in control of the where and when in the document authoring experience. But what about line-of-business or other cases where you want to present the user with a preformatted document with “known” locations within the document that you want to manage/interact with programmatically?
A great example of this is the Bing financial portfolio template. Open Excel 2013 and type “bing” in the search bar to search for the Bing template. Then click on the template and choose Create. When the document loads, take whatever steps necessary to enable the app and you’ll see that the app is essentially pre-loaded in association with the document and can interact with the document by updating stock data even without some user interaction. Also if you search for a stock in the app that is not in the pre-loaded table in the document, you can choose to add it to the table by clicking the Add button. Notice that it adds it to the bottom of the table without you needing to have a location pre-selected where to add the row. This is because the app “knows” locations in the document that it can interact with. This is quite powerful and certainly something that you as a developer should be aware of how to do this. It may provide some neat opportunities for your apps for Office. So let’s get after it.
So we don’t reinvent the wheel here and so that we use a code sample that is available to all, the MSDN team has provided a sample app that will serve as a great starting point for us. Open the Apps for Office: Binding to and validating content controls in Word 2013 code sample landing page. Confirm that you have all the prerequisites in place, download the code sample and open it in Visual Studio.
In this post you used a MSDN code sample that does data binding to content controls within Word. You worked this forward to see how the app can be coupled/associated with a document. Then the OOXML was exposed to help provide understanding that the end result for the document you want to distribute, must have the known location for its manifest file saved within the document. This known location can be a network share, a corporate catalog on an on-premises SharePoint 2013 site or in Office 365 SharePoint Online, or in the Store on office.com. So, essentially the document you want to distribute with the coupled/associated app, must have been saved while accessing the manifest end-point that the users of the document will have access to.
Documents and templates with apps already in them is a great way to provide user experiences where you have done all the complex setup and you have predetermined locations within the document where you can programmatically push and retrieve information at will. New opportunities abound!