共用方式為


Automating Excel by Using Extended Objects

When you develop Excel solutions in Visual Studio, you can use host items and host controls in your solutions. These are objects that extend certain commonly used objects in the Excel object model (that is, the object model that is exposed by the primary interop assembly for Excel), such as the Worksheet and Range objects. The extended objects behave like the Excel objects they are based on, but they add additional features such as new events and data binding capabilities to the objects.

Applies to: The information in this topic applies to document-level projects and application-level projects for Excel 2013 and Excel 2010. For more information, see Features Available by Office Application and Project Type.

Host items and host controls are available in both application-level 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.

Excel Host Items

Excel projects give you access to several host items:

  • Worksheet. This host item contains represents a worksheet in your project. It also acts as a container for managed controls, including host controls and Windows Forms controls, and it maintains information about the controls on its surface. For more information, see Worksheet Host Item.

  • Workbook. This host item represents the workbook in your project, and acts as a container for components that are shared by all worksheets in the workbook. For more information, see Workbook Host Item.

  • ChartSheet. This host item a worksheet in Excel that contains only a chart and exposes events.

    When you add a chart sheet at design time as a new sheet in your Microsoft Office Excel document-level customization project, Visual Studio automatically creates a ChartSheet host item.

    Although a ChartSheet host item is a worksheet in Excel, you cannot add any controls to the chart sheet. If you want to have other controls on a worksheet with a chart, do not use a chart sheet. Instead, you can place a chart as an embedded object on a worksheet by using the Chart host control. For more information, see Chart Control.

Excel Host Controls

There are several host controls for Excel that help you create, organize, and automate workbooks and worksheets. These host controls provide events and data-binding capabilities that their counterparts in the native Excel object model do not have.

For more information about the host controls you can use in Excel projects, see the following topics:

See Also

Tasks

How to: Fill ListObject Controls with Data

How to: Add Chart Controls to Worksheets

How to: Add ListObject Controls to Worksheets

How to: Add NamedRange Controls to Worksheets

How to: Add XMLMappedRange Controls to Worksheets

How to: Resize NamedRange Controls

How to: Resize ListObject Controls

How to: Validate Data When a New Row is Added to a ListObject Control

How to: Map ListObject Columns to Data

Walkthrough: Programming Against Events of a NamedRange Control

Concepts

Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time

Adding Controls to Office Documents at Run Time

Host Items and Host Controls Overview

Programmatic Limitations of Host Items and Host Controls

Other Resources

Controls on Office Documents