Excel 方案Excel solutions

Visual Studio 提供的專案範本,可用以建立 Microsoft Office Excel 的文件層級自訂和 VSTO 增益集。Visual Studio provides project templates you can use to create document-level customizations and VSTO Add-ins for Microsoft Office Excel. 您可以使用這些解決方案自動化 Excel、擴充 Excel 功能和自訂 Excel 使用者介面 (UI)。You can use these solutions to automate Excel, extend Excel features, and customize the Excel user interface (UI). 如需檔層級自訂和 VSTO 增益集之間差異的詳細資訊,請參閱 Office 方案開發總覽 (VSTO)For more information about the differences between document-level customizations and VSTO Add-ins, see Office solutions development overview (VSTO).

適用于: 本主題中的資訊適用于 Excel 的檔 - 層級專案和 VSTO 新增 - 專案。Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Excel. 如需詳細資訊,請參閱 依 Office 應用程式和專案類型提供的功能For more information, see Features available by Office application and project type.

注意

有興趣開發跨多個平臺擴充 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:

自動化 ExcelAutomate Excel

Excel 物件模型會公開您可用來自動化 Excel 的許多類型。The Excel object model exposes many types that you can use to automate Excel. 例如,您可以程式設計的方式建立圖表、格式化工作表,以及設定範圍和儲存格的值。For example, you can programmatically create charts, format worksheets, and set the values of ranges and cells. 如需詳細資訊,請參閱 Excel 物件模型總覽For more information, see Excel object model overview.

在 Visual Studio 中開發 Excel 方案時,您也可以在解決方案中使用 「主項目」 (host items) 和 「主控制項」 (host controls)。When developing Excel solutions in Visual Studio, you can also use host items and host controls in your solutions. 這些都是在 Excel 物件模型中擴充某些常用物件的物件,例如 WorksheetRange 物件。These are objects that extend certain commonly used objects in the Excel object model, such as the Worksheet and Range objects. 這些擴充物件的行為與它們所根據的 Excel 物件一樣,但是這些物件會在物件中加入額外的事件和資料繫結功能。The extended objects behave like the Excel objects they are based on, but they add additional events and data binding capabilities to the objects. 如需詳細資訊,請參閱 使用擴充物件自動化 ExcelFor more information, see Automate Excel by using extended objects.

開發 Excel 的檔層級自訂Develop document-level customizations for Excel

Microsoft Office Excel 文件層級自訂是由與特定活頁簿相關聯的組件所組成。A document-level customization for Microsoft Office Excel consists of an assembly that is associated with a specific workbook. 組件通常是透過自訂 UI 及自動化 Excel 來擴充活頁簿。The assembly typically extends the workbook by customizing the UI and by automating Excel. 不同於與 Excel 本身相關聯的 VSTO 增益集,您在自訂中實作的功能只有在 Excel 中開啟相關聯的活頁簿時才能使用。Unlike a VSTO Add-in, which is associated with Excel itself, functionality that you implement in a customization is available only when the associated workbook is open in Excel.

若要建立 Excel 的檔層級自訂專案,請在 Visual Studio 的 [ 新增專案 ] 對話方塊中,使用 [excel 活頁簿] 或 [excel 範本] 專案範本。To create a document-level customization project for Excel, use the Excel workbook or Excel 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, see Architecture of document-level customizations.

Excel 自訂程式設計模型Excel customization programming model

當您建立 Excel 的文件層級專案時,Visual Studio 會產生為解決方案基礎的數個類別: ThisWorkbookSheet1Sheet2Sheet3When you create a document-level project for Excel, Visual Studio generates several classes that are the foundation of your solution: ThisWorkbook, Sheet1, Sheet2, and Sheet3. 這些類別代表與解決方案相關聯的活頁簿和工作表,並提供撰寫程式碼的起點。These classes represent the workbook and worksheets that are associated with your solution, and they provide a starting point for writing your code.

如需有關您可以在檔層級專案中使用之產生的類別和其他功能的詳細資訊,請參閱 程式檔層級自訂程式For more information about these generated classes and other features you can use in a document-level project, see Program document-level customizations.

開發 Excel 的 VSTO 增益集Develop VSTO Add-ins for Excel

Microsoft Office Excel 的 VSTO 增益集是由 Excel 載入的組件所組成。A VSTO Add-in for Microsoft Office Excel consists of an assembly that is loaded by Excel. 組件通常是透過自訂 UI 及自動化 Excel 來擴充 Excel。The assembly typically extends Excel by customizing the UI and by automating Excel. 不同于與特定活頁簿相關聯的檔層級自訂,您在 VSTO 增益集中所執行的功能不受限於任何單一活頁簿。Unlike a document-level customization, which is associated with a specific workbook, functionality that you implement in a VSTO Add-in is not restricted to any single workbook.

若要建立 Excel 的 VSTO 增益集專案,請在 Visual Studio 的 [ 新增專案 ] 對話方塊中,使用 [excel 活頁簿] 或 [excel 範本] 專案範本。To create a VSTO Add-in project for Excel, use the Excel workbook or Excel 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.

如需 VSTO 增益集運作方式的一般資訊,請參閱 Architecture of VSTO Add-insFor general information about how VSTO Add-ins work, see Architecture of VSTO Add-ins.

Excel 增益集程式設計模型Excel Add-in programming model

當您建立 Excel VSTO 增益集專案時,Visual Studio 會產生名為 ThisAddIn的類別,這是方案的基礎。When you create an Excel VSTO Add-in project, Visual Studio generates a class, called ThisAddIn, which is the foundation of your solution. 這個類別會提供撰寫程式碼的起點,還會向 VSTO 增益集公開 Excel 物件模型。This class provides a starting point for writing your code, and it also exposes the object model of Excel to your VSTO Add-in.

如需 VSTO 增益集中可用之 ThisAddIn 類別和其他 Visual Studio 功能的詳細資訊,請參閱 程式 Vsto 增益集For more information about the ThisAddIn class and other Visual Studio features you can use in a VSTO Add-in, see Program VSTO Add-Ins.

自訂 Excel 的使用者介面Customize the user interface of Excel

有幾種不同的方式可以自訂 Excel 的使用者介面。There are several different ways to customize the user interface of Excel. 有些選項適用於所有專案類型,有些選項則僅限 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.

TaskTask 取得詳細資訊For more information
自訂功能區。Customize the Ribbon. 功能區總覽Ribbon overview
在文件層級自訂的自訂活頁簿工作表,或任何開啟的 VSTO 增益集活頁簿中,加入 Windows Form 控制項或擴充的 Excel 控制項。Add Windows Forms controls or extended Excel controls to a worksheet in the customized workbook for a document-level customization, or in any open workbook for a VSTO Add-in. 如何:將 Windows forms 控制項新增至 Office 檔How to: Add Windows forms controls to Office documents

如何:將圖表控制項加入至工作表How to: Add Chart controls to worksheets

如何:將 ListObject 控制項加入至工作表How to: Add ListObject controls to worksheets

如何:將 NamedRange 控制項加入至工作表How to: Add NamedRange controls to worksheets

檔層級自訂的選項Options for document-level customizations

下表列出的自訂選項僅限文件層級自訂使用。The following table lists customization options that are available only to document-level customizations.

TaskTask 取得詳細資訊For more information
在活頁簿中加入執行窗格。Add an actions pane to the workbook. 動作窗格總覽Actions pane overview

如何:將執行窗格加入 Word 檔或 Excel 活頁簿How to: Add an actions pane to Word documents or Excel workbooks
在工作表中加入對應到 XML 節點的擴充範圍控制項。Add extended range controls that are mapped to XML nodes to a worksheet. 如何:將 XMLMappedRange 控制項加入至工作表How to: Add XMLMappedRange controls to worksheets

VSTO 增益集的選項Options for VSTO Add-ins

下表列出的自訂選項僅限 VSTO 增益集使用。The following table lists customization options that are available only to VSTO Add-ins.

TaskTask 取得詳細資訊For more information
建立自訂工作窗格。Create a custom task pane. 自訂工作窗格Custom task panes
標題Title 描述Description
Excel 物件模型總覽Excel object model overview 提供 Excel 物件模型所提供的主要類型的概觀。Provides an overview of the main types provided by the Excel object model.
使用擴充物件自動化 ExcelAutomate Excel by using extended objects 提供可以用在 Excel 方案中之擴充物件 (由 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 Excel solutions.
Excel 方案的全球化與當地語系化Globalization and localization of Excel solutions 包含會在有非英文設定的 Windows 電腦上執行 Excel 方案之特殊考量的相關資訊。Contains information about special considerations for Excel solutions that will be run on computers that have non-English settings for Windows.
Office 檔上的 Windows Forms 控制項總覽Windows Forms controls on Office documents overview 描述如何在 Excel 工作表中加入 Windows Form 控制項。Describes how you can add Windows Forms controls to Excel worksheets.
逐步解說:建立 Excel 的第一個檔層級自訂Walkthrough: Create your first document-level customization for Excel 示範如何建立 Excel 的基本文件層級自訂。Demonstrates how to create a basic document-level customization for Excel.
逐步解說:建立 Excel 的第一個 VSTO 增益集Walkthrough: Create your first VSTO Add-in for Excel 示範如何建立 Excel 的基本 VSTO 增益集。Demonstrates how to create a basic VSTO Add-in for Excel.
逐步解說:在執行時間于 VSTO 增益集專案中,將控制項加入工作表Walkthrough: Add controls to a worksheet at run time in VSTO Add-in project 示範如何使用 VSTO 增益集,於執行階段在工作表中加入 Windows Form 按鈕、 NamedRangeListObjectDemonstrates how to add a Windows Forms button, a NamedRange, and a ListObject to a worksheet at run time by using a VSTO Add-in.
瞭解共同撰寫和增益集Understand co-authoring and Add-ins 說明您可能需要對方案進行的調整,以配合共同工作。Describes adjustments you might need to make to your solutions to accommodate coauthoring.
Office 開發中的 Excel 2010Excel 2010 in Office development 提供開發 Excel 方案的相關文章和參考文件連結。Provides links to articles and reference documentation about developing Excel solutions. 非專屬於使用 Visual Studio 的 Office 程式開發。These are not specific to Office development using Visual Studio.