Word 解决方案Word solutions

Visual Studio 提供可用于创建适用于 Microsoft Office Word 的文档级自定义项和 VSTO 外接程序的项目模板。Visual Studio provides project templates you can use to create document-level customizations and VSTO Add-ins for Microsoft Office Word. 你可以使用这些解决方案来实现 Word 自动化、扩展 Word 功能以及自定义 Word 用户界面 (UI)。You can use these solutions to automate Word, extend Word features, and customize the Word user interface (UI). 有关文档级自定义项和 VSTO 外接程序之间的差异的详细信息,请参阅Office 解决方案(开发)概述 VSTOFor more information about the differences between document-level customizations and VSTO Add-ins, see Office solutions development overview (VSTO).

适用于: 本主题中的信息适用于文档-级别项目和 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.

Note

有兴趣开发跨多个平台扩展 Office 体验的解决方案?Interested in developing solutions that extend the Office experience across multiple platforms? 查看新的 " Office 外接程序" 模型Check out the new Office Add-ins model. 与 VSTO 外接程序和解决方案相比,Office 外接程序的占用空间较小,可以使用几乎任何 web 编程技术(例如 HTML5、JavaScript、CSS3 和 XML)生成它们。Office Add-ins have a small footprint compared to VSTO Add-ins and solutions, and you can build them by using almost any web programming technology, such as HTML5, JavaScript, CSS3, and XML.

本主题提供以下信息:This topic provides the following information:

自动执行 WordAutomate Word

Word 对象模型公开了许多可用于实现 Word 自动化的类型。The Word object model exposes many types that you can use to automate Word. 例如,可以通过编程方式创建表格、设置文档格式以及设置范围和段落中的文本。For example, you can programmatically create tables, format documents, and set the text in ranges and paragraphs. 有关详细信息,请参阅Word 对象模型概述For more information, see Word object model overview.

在 Visual Studio 中开发 Word 解决方案时,还可以使用解决方案中的 主机项主机控件When developing Word solutions in Visual Studio, you can also use host items and host controls in your solutions. 这些对象可扩展 Word 对象模型中的某些常用对象,例如 DocumentContentControl 对象。These are objects that extend certain commonly used objects in the Word object model, 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. 有关详细信息,请参阅使用扩展对象实现 Word 自动化For more information, see Automate Word by using extended objects.

开发 Word 的文档级自定义项Develop document-level customizations for Word

Microsoft Office Word 的文档级自定义项包含与特定文档相关联的程序集。A document-level customization for Microsoft Office Word consists of an assembly that is associated with a specific document. 此程序集通常可通过自定义 UI 和自动化 Word 来扩展文档。The assembly typically extends the document by customizing the UI and by automating Word. 不同于与 Word 自身相关联的 VSTO 外接程序,在自定义中实现的功能只有当关联文档在 Word 中打开时才可用。Unlike a VSTO Add-in, which is associated with Word itself, functionality that you implement in a customization is available only when the associated document is open in Word.

若要创建 Word 的文档级自定义项目,可使用 Visual Studio 的 “新建项目” 对话框中的“Word 文档”或“Word 模板”项目模板。To create a document-level customization project for Word, use the Word Document or Word Template project templates in the New Project dialog box of Visual Studio. 有关详细信息,请参阅如何:在 Visual Studio 中创建 Office 项目For more information, see How to: Create Office projects in Visual Studio.

有关文档级自定义项如何工作的详细信息,请查看文档级自定义项的体系结构For more information about how document-level customizations work, Architecture of document-level customizations.

Word 自定义项编程模型Word customization programming model

在创建 Word 的文档级项目时,Visual Studio 将生成一个名为 ThisDocument的类,这是解决方案的基础。When you create a document-level project for Word, Visual Studio generates a class, called ThisDocument, which is the foundation of your solution. 此类表示与解决方案相关联的文档,并提供用于编写代码的起点。This class represents the document that is associated with your solution, and it provides a starting point for writing your code.

有关 ThisDocument 类以及可以在文档级项目中使用的其他功能的详细信息,请参阅程序文档级自定义项For more information about the ThisDocument class and other features you can use in a document-level project, see Program document-level customizations.

开发 Word 的 VSTO 外接程序Develop VSTO Add-ins for Word

Microsoft Office Word 的 VSTO 外接程序包含由 Word 加载的程序集。A VSTO Add-in for Microsoft Office Word consists of an assembly that is loaded by Word. 此程序集通常可通过自定义 UI 和自动化 Word 来扩展 Word。The assembly typically extends Word by customizing the UI and by automating Word. 不同于与特定文档相关联的文档级自定义项,在 VSTO 外接程序中实现的功能不局限于任何单个文档。Unlike a document-level customization, which is associated with a specific document, functionality that you implement in a VSTO Add-in is not restricted to any single document.

若要创建 Word 的 VSTO 外接程序项目,可使用 Visual Studio 的 “新建项目” 对话框中的 Word 外接程序项目模板。To create a VSTO Add-in project for Word, use the Word Add-in project templates in the New Project dialog box of Visual Studio. 有关详细信息,请参阅如何:在 Visual Studio 中创建 Office 项目For more information, see How to: Create Office projects in Visual Studio.

有关 VSTO 外接程序工作原理的常规信息,请参阅 Architecture of VSTO Add-insFor general information about how VSTO Add-ins work, see Architecture of VSTO Add-ins.

Word 外接程序编程模型Word Add-in programming model

在创建 Word VSTO 外接程序项目时,Visual Studio 将生成一个名为 ThisAddIn的类,这是解决方案的基础。When you create a Word VSTO Add-in project, Visual Studio generates a class, called ThisAddIn, which is the foundation of your solution. 此类提供编写代码的起点,并且还对 VSTO 外接程序公开 Word 的对象模型。This class provides a starting point for writing your code, and it also exposes the object model of Word to your VSTO Add-in.

有关 ThisAddIn 类和可在 VSTO 外接程序中使用的其他功能的详细信息,请参阅PROGRAM Vsto 外接程序For more information about the ThisAddIn class and other features you can use in a VSTO Add-in, see Program VSTO Add-ins.

自定义 Word 的用户界面Customize the user interface of Word

可通过若干不同方式来自定义 Word 的用户界面。There are several different ways to customize the user interface of Word. 某些选项适用于所有项目类型,而其他选项仅适用于 VSTO 外接程序或文档级自定义项。Some options are available to all project types, and other options are available only to VSTO Add-ins or document-level customizations.

适用于所有项目类型的选项Options for all project types

下表列出了可用于文档级自定义项和 VSTO 外接程序的自定义选项。The following table lists customization options that are available to both document-level customizations and VSTO Add-ins.

任务Task 更多相关信息For more information
自定义功能区。Customize the Ribbon. 功能区概述Ribbon overview
将 Windows 窗体控件或扩展的 Word 控件添加到(文档级自定义项的)自定义文档中,或添加到(VSTO 外接程序的)任何打开文档中。Add Windows Forms controls or extended Word controls to the customized document (for a document-level customization) or to any open document (for a VSTO Add-in). 如何:向 Office 文档添加 Windows 窗体控件How to: Add Windows Forms controls to Office documents

如何:向 Word 文档添加内容控件How to: Add content controls to Word documents

如何:向 Word 文档添加书签控件How to: Add bookmark controls to Word documents

文档级自定义项的选项Options for document-level customizations

下表列出了仅适用于文档级自定义项的自定义选项。The following table lists customization options that are available only to document-level customizations.

任务Task 更多相关信息For more information
将操作窗格添加到文档。Add an actions pane to the document. 操作窗格概述Actions pane overview

如何:向 Word 文档或 Excel 工作簿添加操作窗格How to: Add an actions pane to Word documents or Excel workbooks
将扩展的 XMLNode 和 XMLNodes 控件添加到文档图面中。Add extended XMLNode and XMLNodes controls to the document surface. 如何:将 XMLNode 控件添加到 Word 文档How to: Add XMLNode controls to Word documents

如何:将 XMLNodes 控件添加到 Word 文档How to: Add XMLNodes controls to Word documents

适用于 VSTO 外接程序的选项Options for VSTO Add-ins

下表列出了仅适用于 VSTO 外接程序的自定义选项。The following table lists customization options that are available only to VSTO Add-ins.

任务Task 更多相关信息For more information
创建自定义任务窗格。Create a custom task pane. 自定义任务窗格Custom task panes
TitleTitle 描述Description
Word 对象模型概述Word object model overview 概述由 Word 对象模型提供的主类型。Provides an overview of the main types provided by the Word object model.
使用扩展对象实现 Word 自动化Automate Word by using extended objects 提供有关可在 Word 解决方案中使用的扩展对象(由 Visual Studio Tools for Office RuntimeVisual Studio Tools for Office runtime提供)的信息。Provides information about extended objects (provided by the Visual Studio Tools for Office RuntimeVisual Studio Tools for Office runtime) that you can use in Word solutions.
Office 文档上的 Windows 窗体控件概述Windows Forms controls on Office documents overview 介绍如何将 Windows 窗体控件添加到 Word 文档。Describes how you can add Windows Forms controls to Word documents.
演练:创建您的第一个 Word 文档级自定义项Walkthrough: Create your first document-level customization for Word 演示如何创建 Word 的基本文档级自定义项。Demonstrates how to create a basic document-level customization for Word.
演练:创建您的第一个 Word VSTO 外接程序Walkthrough: Create your first VSTO Add-in for Word 演示如何创建 Word 的基本 VSTO 外接程序。Demonstrates how to create a basic VSTO Add-in for Word.
演练:在运行时在 VSTO 外接程序中将控件添加到文档Walkthrough: Add controls to a document at run time in a VSTO Add-in 演示如何使用 VSTO 外接程序在运行时将 Windows 窗体按钮和 RichTextContentControl 添加到文档。Demonstrates how to add a Windows Forms button and a RichTextContentControl to a document at run time by using a VSTO Add-in.
Office 开发中的 Word 2010Word 2010 in Office development 提供关于开发 Word 解决方案(不特定于使用 Visual Studio 的 Office 开发)的文章和参考文档的链接。Provides links to articles and reference documentation about developing Word solutions (not specific to Office development using Visual Studio).