使用扩展对象实现 Word 自动化Automate Word by using extended objects

当在 Visual Studio 中开发 Word 解决方案时,可以使用解决方案中的 宿主项宿主控件When you develop Word solutions in Visual Studio, you can use host items and host controls in your solutions. 这些对象可扩展 Word 对象模型(即由 Word 主互操作程序集公开的对象模型)中的一些常用对象,例如 DocumentContentControl 对象。These are objects that extend certain commonly used objects in the Word object model (that is, the object model that is exposed by the primary interop assembly for Word), such as the Document and ContentControl objects. 扩展对象的行为类似于其所基于的 Word 对象,但它们可以将其他事件和数据绑定功能添加到对象。The extended objects behave like the Word objects they are based on, but they add additional events and data binding capabilities to the objects.

适用于: 本主题中的信息适用于文档-级别项目和 VSTO 添加-Word 的项目中。Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Word. 有关详细信息,请参阅按 Office 应用程序和项目类型提供的功能For more information, see Features available by Office application and project type.

虽然使用宿主项和宿主控件所在的上下文对于每种类型的解决方案有所不同,但它们均可用于 VSTO 外接程序和文档级自定义项。Host items and host controls are available in both VSTO Add-ins and document-level customizations, although the context in which these can be used is different for each type of solution. 有关详细信息,请参阅主机项和主机控件概述For more information, see Host items and host controls overview.

文档宿主项Document host item

Word 项目可授予你访问 Document 宿主项的权限。Word projects give you access to the Document host item. Document 宿主项还可充当其他控件(包括宿主控件和 Windows 窗体控件)的容器,并且还可保留有关其界面上的控件的信息。The Document host item acts as a container for other controls, including host controls and Windows Forms controls, and it maintains information about the controls on its surface. Document 宿主项还提供了大部分与 Document 类相同的成员,该类是 Word 对象模型中的对应类。The Document host item also provides most of the same members as the Document class, which is the corresponding class in the object model of Word.

有关详细信息,请参阅文档主机项For more information, see Document host item.

Word 宿主控件Word host controls

有多个可用于 Word 的宿主控件,这些控件有助于你创建、组织和自动处理文档。There are several host controls for Word that help you create, organize, and automate documents. 它们的大部分功能包含了导入、呈现和保护数据。Most of their functionality involves importing, presenting, and protecting data. 这些宿主控件可提供本机 Word 对象模型中的相应控件所无法提供的事件和数据绑定功能。These host controls provide events and data-binding capabilities that their counterparts in the native Word object model do not have.

在文档级项目中,可以在设计时向文档中添加宿主控件,或在运行时添加内容控件和书签控件。In document-level projects, you can add any host control to your document at design time, or you can add content controls and bookmark controls at run time. 在 VSTO 外接程序项目中,可以在运行时向任何打开的文档中添加内容控件和书签控件。In VSTO Add-in projects, you can add content controls and bookmark controls to any open document at run time.

有关可以在 Word 项目中使用的宿主控件的详细信息,请参阅以下主题:For more information about the host controls you can use in Word projects, see the following topics:

请参阅See also