Compartilhar via


Microsoft Word 2010 Developer Building Blocks

Extending Microsoft Word 2010 is one of the most effective ways to augment content and enable richer collaboration around documents.  There are many ways to extend Microsoft Word 2010 and integrate user-friendly and powerful document editing into your application.  Extending Word is the most common way to develop for Microsoft Office.

This blog is inactive.
New blog: EricWhite.com/blog

Blog TOCThis post is one in a series on Microsoft Office 2010 application development. These posts will be published in the future as part of an MSDN article. As usual, after the MSDN article is published, I’ll place pointers in the blog posts to the article on MSDN.

  1. Office/SharePoint Building Blocks and Developer Stories
  2. Overview of Office 2010 Application Development
  3. Office Application Scenarios
  4. Understanding the Three Approaches to Office Development using VSTO
  5. What is the Difference between ‘Word Automation’ and ‘Word Automation Services’?
  6. Understanding the Architecture of Office 2010 Managed Add-Ins and Customizations
  7. Understanding the Difference between Custom Task Panes and Action Panes
  8. Microsoft Word 2010 Developer Building Blocks
  9. Comparing Excel Automation to Excel Services

In this series of posts, I'll be publishing a post on each of the Office client applications, listing the developer building blocks for it.  I put the various developer building blocks into one of four categories:

·         User Interface Extensions – You use these building blocks to create custom ribbons, custom user interfaces, extend content menus, and more.

·         Canvas Extensions – Available only in Microsoft Word and Microsoft Excel , canvas extensions are those extensibility points that enable you to add controls to the surface of a document or spreadsheet.  You can add controls to the surface of a document to create more interactivity for users.

·         Programmability Extensions – In combination with user interface and canvas extensions, you use programmability extensions to build customizations and add-ins.

·         Supported for Previous Versions – listed for completeness, instead of using these legacy technologies, Microsoft recommends using newer approaches for programmability using managed add-ins, customizations, and user interface extensions.

In addition to extending the Word user interface on client computers, developers take advantage of services on servers such as Word Automation Services or WCF services to build distributed applications with rich functionality.  Using the Open XML SDK on servers enables you to develop enterprise-quality bulk document generation applications that perform well and are robust.

Developer Center: Word Developer Center

Technical Articles: Word 2010 Technical Articles

Technical Articles: Word 2007 Technical Articles

Videos: Word Visual How Tos

User Interface Extensions

Building Block

Description

Action Pane

Extend the user interface by creating a customizable pane for document-level solutions.

Backstage

Customize the backstage view enables you to display information about documents to users.

Context Menu

Customize the context menu to make custom features easy to use.

Custom Task Pane

Extend the user interface by creating a customizable pane for application-level solutions.

Document Information Panel

Enable users to enter metadata about a document.

Ribbon

Customize the ribbon to augment the editing experience of the document and make the features of your add-in more discoverable.

Canvas Extensions

Building Block

Description

Content Controls

Use content controls to give structure to documents.

User Controls

Add Windows Forms or WPF controls to the surface of a document to build interactive documents.

Programmability Extensions

Building Block

Description

Application Level Add-Ins

Develop a managed add-in that users can use to interact with Word documents.  An installed solution can operate on any open document.

Automation

Use automation to build an executable (external to Word) that can control Word, including starting Word, setting and getting ranges of text, saving the document, and more.

AltChunk

Use the altChunk functionality of Open XML to merge content from other Open XML documents, HTML documents, and more into a new document.

Business Data Connectivity Object Model

Connect to BCS data through SharePoint.

Custom XML Parts

Embed and associate XML documents in a word-processing document.

Document Level Customization

Develop a managed add-in that users can use to interact with Word documents.  The solution is attached to a specific document or template.

Local Database

Include a database file, such as a SQL Server Express (.mdf) file or a Microsoft Office Access (.mdb) file, in your Visual Studio Tools for Office solution.

Open XML SDK

Use the Open XML SDK to generate Word documents.  In addition to generating documents, the Open XML SDK enables developers to make extensive modifications to a document such as replacing the contents of a paragraph.

Visual Basic for Applications

Use Visual Basic for Applications (unmanaged code) that is connected to and persisted with a specific document.

Supported for Previous Versions

Building Block

Description

ActiveX Controls on Word Document

Use ActiveX controls on the surface of a document to create interactive documents.

ActiveX Controls on User Form

Use ActiveX controls on a user form to build interactive solutions.

COM Extensions

Use unmanaged code to create a COM based add-in.

Command Bars

Customize command bars to enable users to carry out actions.  Instead of using command bars, we recommend extending the ribbon.

Smart Documents

Use XML to define custom task pane content that automatically synchronizes help, instructions, and programmable controls with the user's position in the document.

Action Pane

An actions pane is a customizable task pane that is attached to a specific Microsoft Office Word document in a document-level solution.  It is hosted inside the Office task pane along with other built-in task panes.  This real-estate can be docked to the right, bottom, left, or right of the document or spreadsheet.  It can also be a floating window.  You can use Windows Forms controls or WPF controls in an action pane.

SDK: Actions Pane Overview

How Do I: Use WPF Controls Inside an Excel Actions Pane?

MSDN: Features Available by Office Application and Project Type

Blog Post: Understanding the Difference between Custom Task Panes and Action Panes

ActiveX Controls on Word Document

You can add controls to your documents to create interactive documents, such as online forms.  Instead of using ActiveX controls, Microsoft recommends using Windows Forms or WPF controls.

MSDN: Using ActiveX Controls on Word Documents

ActiveX Controls on User Form

You can use ActiveX controls to create user forms.  Instead of building user forms using ActiveX, Microsoft recommends building forms using Windows Forms or WPF.

MSDN: Effectively Using ActiveX Form Controls in Microsoft Word

MSDN: OLE Programmatic Identifiers

AltChunk

The altChunk functionality of the Open XML file formats enables easy merging of documents.  You can merge content from multiple sources (other Open XML documents, HTML, plain text, and more) into a single document.  After using the Open XML SDK to set up the document that imports alternative content, if you want to convert the document so that the new content is transformed to typical Open XML WordprocessingML, you need to open and save the document using Word 2010.  Alternatively, you can use Word Automation Services to process the document and import the alternative content.

Blog Post: How to Use altChunk for Document Assembly

Blog Post: Comparison of altChunk to the DocumentBuilder Class

Blog Post: Formats Supported for altChunk

Blog Post: Inserting Content That Contains Images Using altChunk

Technical Article: Developing with SharePoint 2010 Word Automation Services

Application Level Add-Ins

This type of add-in’s functionality is available regardless of which document, spreadsheet, or presentation is opened.  An example of this variety is a department-wide or corporate-wide application that enables some level of functionality that every employee of the department or corporation needs to access on a regular basis.  As an example, Lexis for Microsoft Office is an Office customization targeting legal firms.  Users need to execute the same code for every document, so it is implemented as an application-level managed add-in.

MSDN: Office Development in Visual Studio

MSDN: Architecture of Application-Level Add-Ins

MSDN: Programming Application-Level Add-Ins

MSDN: Managing Task Panes in Multiple Word and InfoPath Documents

MSDN: Managing Custom Task Panes in Multiple Application Windows

MSDN: Expose an object in an application-level add-in to other Microsoft Office solutions.

SDK: Microsoft.Office.Interop.Word Namespace

Blog Post: Understanding the Three Approaches to Office Development

Automation

Word Automation is a technology where you can write a .NET application that uses the Word client executable to accomplish some task such as creating a document, querying a document for content, or modifying the content of a document.  Its roots are COM – in addition to using .NET to link to the Primary Interop Assemblies, you can use C++ or VB6 (or any other technology that can consume COM) to automate the Word client application.  In other words, you write a program that runs Word.  There is a rich object model that you can use to manipulate paragraphs, ranges, comments, etc.  This technology has been around for years.  If you are an experienced Office developer who needed to generate a large number of documents (prior to the introduction of the Open XML SDK), then you have probably used Word Automation at one time or another.

The user operates a .NET managed application that in turn runs the Word 2007 or Word 2010 client.

 

Instead of generating word-processing documents using Word Automation, we recommend using the Open XML SDK together with Word Automation Services.  The Open XML SDK and Word Automation Services are ‘server hardened’.

Blog Post: What is the Difference between ‘Word Automation’ and ‘Word Automation Services’?

Backstage

Clicking the File tab takes you to the customizable Microsoft Office Backstage view. Backstage view helps you discover and use the features that fall outside the authoring features on the Ribbon. Ribbon, Mini toolbar and galleries all help you work in your documents; backstage view helps you work with your documents.

The following screen clipping shows the customizable backstage view.

 

Backstage View Developer Center

Technical Article: Introduction to the Office 2010 Backstage View for Developers

Technical Article: What's New for Developers in Office 2010

Technical Article: Customizing the Office 2010 Backstage View for Developers

Business Data Connectivity Object Model

Business Connectivity Services (BCS) brings line-of-business data into SharePoint 2010.  SharePoint 2010 makes this data available to the Office client applications through the Business Data Connectivity Object Model (BDC OM).  The following diagram shows how the Office clients (J) access BCS data through the BDC client runtime (K).

 

Business Connectivity Services Resource Center

TechNet: Business Connectivity Services overview

MSDN: Understanding Business Connectivity Services Client Cache to Optimize Your Solutions

MSDN: When Is the Cache Refreshed?

Blog: Overview of BCS Advanced Code-Based Solutions

COM Extensions

You can build a Component Object Model (COM) Office add-in using C++, VB6, or other languages that can consume COM libraries.  Microsoft does not recommend using COM extensions for new development.  Microsoft does not recommend building COM based add-ins using C# or VB.NET.  Instead, you should build an application-level add-in or a document-level customization using Visual Studio.

MSDN: Creating COM Add-ins in Office Developer

MSDN: Building COM Add-ins for the Visual Basic Editor

Office Online: Enable or disable add-ins in Office programs

Command Bars

The command bars object model exposes objects, collections, properties, and methods that you can use to show, hide, and modify existing command bars and command bar controls, and create new ones.  In addition, you can specify a Microsoft® Visual Basic® for Applications (VBA) procedure to run when a user clicks a command bar button or to respond to events triggered by a command bar or command bar control. Instead of using command bars, Microsoft recommends extending the ribbon.

MSDN: Manipulating Command Bars and Command Bar Controls with VBA Code

How To Use Automation to Create Office Command Bars and Controls with Visual Basic .NET

Content Controls

Content controls are bounded and potentially labeled regions in a document that serve as containers for specific types of content. Using content controls in Word 2007 and Word 2010, you can create document templates with rich, structured blocks of content.

Word Content Controls Resource Center

How to: Add Content Controls to Word Documents

Walkthrough: Binding Content Controls to Custom XML Parts

Video: How Do I: Use Word Content Controls?

Visual How-To: Mapping Word 2007 Content Controls to Custom XML Using the XMLMapping Object

Context Menu

Customizing the context menu provides a convenient way for users to access functionality for your application-level add-in or document-level customization.

Technical Article: Customizing Context Menus in Office 2010

Custom Task Pane

Custom task panes consist of screen real-estate that co-exists with the open document or spreadsheet within the Office client.  This real-estate can be docked to the right, bottom, left, or right of the document or spreadsheet.  It can also be a floating window.  You can use Windows Forms controls or WPF controls in an action pane.

MSDN: Custom Task Panes Overview

MSDN: Managing Custom Task Panes in Multiple Application Windows

Blog Post: Understanding the Difference between Custom Task Panes and Action Panes

Custom XML Parts

Custom XML parts enable you to store arbitrary XML of your own design in the package of a document.   The most common use for custom XML parts is to associate data in the parts with content controls in the document.  However, you can use custom XML parts for any purpose that you like.  For example, your managed add-in may need to keep some data for some important functionality.  It can keep that data in a custom XML part, so that the data always accompanies the document.

Walkthrough: Binding Content Controls to Custom XML Parts

Video How to: Binding Content Controls to Custom XML Parts

Blog Post: Creating Data-Bound Content Controls using the Open XML SDK and LINQ to XML

Document Level Customization

Using document-level customizations,.NET managed assemblies (code-signed for security purposes) are attached directly to each document, so if you send the document to a new user, they can open the document and use the custom functionality without explicitly installing an add-in.  For example, a tax analysis department needs to systematically analyze documents for their tax implications and then communicate that analysis back to the document author.  The result of that analysis is associated with a specific document, so it makes sense to build a document-level customization that manages the process of assessing and optimizing the tax implications of that document.  A typical deployment might include an application-level add-in that is used by the tax analysis firm that produces a document that is customized with a document-level customization.

MSDN: Developing Document-Level Customizations for Word

MSDN: Architecture of Document-Level Customizations

MSDN: Cached Data in Document-Level Customizations

How Do I: Attach or Detach a VSTO Assembly from a Word Document?

Document Information Panel

Often in document management systems, users are asked—usually at the point when they are saving their documents—to provide metadata (properties) for their documents.  Document information panels enable users to specify all the properties on a document at once, in one place, at any point when they are working with that document.

SDK: Document Information Panel Overview

Local Database

You can include a database file, such as a SQL Server Express (.mdf) file or a Microsoft Office Access (.mdb) file, in your Visual Studio Tools for Office solution. This enables end users to maintain a local database in situations where maintaining a centralized database is not required, for example in a inventory solution where the data is embedded inside the document, and used on a single computer.

MSDN: Using Local Database Files in Office Solutions Overview

Open XML SDK

You can work directly with the Open XML file formats (DOCX, XLSX, and PPTX files) using the Open XML SDK.  When you use the Open XML SDK, you are not directly customizing Microsoft Office, but are instead directly generating or modifying Office documents.  The bulk generation of documents using the Open XML SDK is much faster than automating Word.

Open XML Developer Center

Blog: Eric White’s Blog

Blog: Zeyad Rajabi’s Open XML SDK Blog Map

Ribbon

The key benefit of customizing the ribbon is that it makes features of your application more discoverable.  Users can see tabs that you add to the ribbon.  They click on the tab, and then see buttons and other controls that help them understand the capabilities of your Office application.

MSDN: Ribbon Overview

How to: Get Started Customizing the Ribbon

Walkthrough: Creating a Custom Tab by Using the Ribbon Designer

Walkthrough: Creating a Custom Tab by Using Ribbon XML

Smart Documents

Developers can create Word or Excel Smart Documents augmented with programmable pieces that help users create or modify them. Reusing boilerplate text, implementing business rules for how a document should be formatted or completed, and routing a document through an approval process are all procedures that Office Smart Documents can simplify.

Instead of using Smart Documents, we recommend building application-level or document-level managed add-ins.

MSDN Magazine: Create Word and Excel Smart Documents with C++ and XML

SDK: Smart Documents SDK

SDK: Understanding XML Expansion Packs

Office Online: About smart documents

User Controls

You can add Windows Forms or WPF controls to the surface of a document, enabling richer interaction in the document for users.  You can bind controls to data.

MSDN: Windows Forms Controls on Office Documents Overview

MSDN: Limitations of Windows Forms Controls on Office Documents

MSDN: Using Windows Forms Controls on Word Documents

MSDN: Binding Data to Controls in Office Solutions

How to: Populate Documents with Data from a Database

VisualBasicforApplications

Visual Basic for Applications (VBA) is an implementation of Microsoft's event-driven programming language Visual Basic 6.  Most Microsoft Office applications include an integrated editing and debugging environment for VBA.  VBA enables developers to build user defined functions and automate processes that access the Word document and customize the user interface.  Applications built with the 64-bit version of Office 2010 can reference larger address spaces, and therefore provide the opportunity to use more physical memory than ever, potentially reducing the overhead spent moving data in and out of physical memory.

Technical Article: Getting Started with VBA in Office 2010

Technical Article: Getting Started with VBA in Word 2010

MSDN: Signing a VBA Project

MSDN: Word Object Model Overview

Office online:  Digitally sign a macro project

Technical Article: Compatibility Between the 32-bit and 64-bit Versions of Office 2010

MSDN: Interoperability between VBA and Visual Studio Tools for the Office System (3.0)

Comments

  • Anonymous
    December 15, 2010
    The comment has been removed

  • Anonymous
    January 15, 2011
    Hello friends, I want to change the position of the keys on the keyboard to put the vouels and puntuation in left hand only, is this posible? Thanks.

  • Anonymous
    June 28, 2011
    Who is the partner of BUILGATE or VULGATE or BUILDGATE (actually I didn't know the spelling of that name) in developing Microsoft Word or MS Word? Quick Answer please. . .

  • Anonymous
    April 04, 2013
    I want to find out how to use building blocks gallery controls for using contractual text.  I'm a user and this page is aimed at programmers.  Could we please have some advice for lay people.  Help says that this functionality can be used but does not explain how.

  • Anonymous
    December 23, 2013
    Nice info - a great compilation of arcane programmer features! But far too complicated for any normal Word user to learn or use, since we all are responsible for getting a crushing amount of actual daily work done. Word is being made far too complicated, seemingly for the benefit of developers, rather than easy to use for the benefit of users. A user may want to quickly and easily build a custom data entry screen that appears when a user opens a word.doc, provides pick lists and data entry fields, and then populates the document with this info. But that user may NOT want to have to distribute it as a template, especially if they are working in Sharepoint. The typical user DOES NOT want to have to learn to use Visual Basic, or distribute documents that need to be digitally signed and/or may plunge those who try to use the document, into the inscrutable mysteries of the Trust Center. The typical user DOES NOT want to embed ActiveX or cascading style sheets or any other obscure 'programming controls'. The typical user CAN'T spend weeks trying to learn new, esoterically-documented features built by people who seem to have lost sight of what it really means to be a typical Word user. Typical users DON'T want all that madness - they generally don't have the ability, time, or discretionary company spending freedom to hire and direct consultants and programmers - having to do so, is itself a telling symptom of a deficiently-designed application - one that gives average users no easy, practical way to automate their crushing workload and enable themselves to work easier, faster or smarter.  

  • Anonymous
    December 23, 2013
    Hi Bob, You are absolutely right - most users do not want to use any of these technologies.  They want to just create and edit documents. However, main point here is that in addition to being perhaps the single most used application in the world (in all its various versions), Word (and Office) is a development platform.  While most users don't want to use these technologies, developers DO want to use these technologies to create solutions that incorporate Word as an integral part of the workflow.  There are literally 10's of thousands of 'applications' that are built on Word, to do things like legal research while writing legal documents, customized creation of sales material, formalized procedures for creating RFPs for large manufacturing companies, and etc. The large number and varieties of technologies are due, I think, to the age of Word, and its existence through continually evolving developer best practices.  Developer technologies come and go, but if Word supports a given technology, such support is rarely removed.  For instance, ActiveX is really long in the tooth now, and there are much better approaches to building Word applications, but because there are companies out there with mission critical applications built using ActiveX, Office still supports it.  VBA has dated language design when compared to C# or VB.NET, but there are literally hundreds of millions of lines of VBA code still in use today, so it still needs to be supported where it makes sense.  It WAS removed from the Windows RT Office (I think because of locking down security, and also perhaps power consumption considerations.)  But developer technologies are rarely removed, so Word has a lot. One technology that I'm really excited about are the new Office Apps written in JavaScript.  This post predates this new JavaScript technology, so it is not mentioned.  I think that the JavaScript approach solves a lot of the problems inherent in other developer technologies that we use to extend Word. So yes, users don't need these things, but developers, IT departments, and small commercial vendors of vertical applications do. Cheers, Eric