In Part 1 I discussed about
- Document generation using Content Controls and Open XML 2.0 SDK
- Creating Word templates
- Implementation and Samples
In Part 2 I discussed about
- List of functionalities that can be achieved using the utility/source code
- Description regarding Samples provided with utility
- New samples added in this update
In this part I’ll discuss about the sample that shows one of the ways to “Refresh the document from within the Word(e.g. right click on document and click Refresh) using document-level customizations for Word 2007 and Word 2010“. On click of Refresh Document the content of the document is refreshed as displayed below
Project “WordDocumentGenerator.WordRefreshableDocumentAddin” has been added to the utility for this sample. The steps followed for creating this sample are listed below
- Added a new Word 2010 Document project as displayed below
- Updated the document by adding the content controls as displayed below
- Added a new Command bar button i.e. “Refresh Data” to the Command bar. On click of this button the document will be refreshed. The common scenario will be to refresh data from the Service. “WordDocumentGenerator.WordRefreshableDocumentAddin” is the document level customization project. This project references “WordDocumentGenerator.Library” and “WordDocumentGenerator.Client” projects.
The code snippet to add a new Command bar button is
On click of refresh data the main steps are
1. Get package steam from the document
2. Call the Service/Client method that generates/refreshes the document. This can be a Server or a direct call. In this method it’s a direct call.
3. Update the document contents
These are partial code snippets to show the code flow. For complete sample please download the source code.
- For more information about Programming Document level customizations
- For more information about methods of OPCHelper class please visit http://msdn.microsoft.com/en-us/library/ff191178.aspx