如何在 C# 中将 'public partial class ThisWorkbook' 添加到 VSTO 应用程序?

How do you add a 'public partial class ThisWorkbook' to a VSTO application in C#?

我正在尝试将 ActionPane 添加到 Excel VSTO 加载项。我需要访问 ThisWorkbook.ActionsPane 集合来添加我的操作面板。

Microsoft 文档位于:

https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-add-an-actions-pane-to-word-documents-or-excel-workbooks?view=vs-2019

说:

To show the actions pane, add the user control to the Controls property of the ThisDocument.ActionsPane field (Word) or ThisWorkbook.ActionsPane field (Excel).

Add the following code to the ThisDocument or ThisWorkbook class as a class-level declaration (do not add this code to a method).

这意味着我需要向 VSTO 解决方案添加 ThisWorkbook class。我的问题是:

您需要区分文档级和应用程序级加载项。

操作窗格是一个可自定义的文档操作任务窗格,附加到特定的 Microsoft Office Word 文档或 Microsoft Office Excel 工作簿。操作窗格与其他内置任务窗格一起托管在 Office 任务窗格中,例如 Excel 中的 XML 源任务窗格或 Word 中的样式和格式任务窗格。您可以使用 Windows Forms 控件或 WPF 控件来设计操作窗格用户界面。

如果您正在开发文档级加载项,请阅读 How to: Add an Actions Pane to Word Documents or Excel Workbooks 文章中有关操作窗格的更多信息。

如果您正在开发应用程序级加载项,您可能有兴趣使用 Custom task panes. Task panes are user interface panels that are typically docked to one side of a window in a Microsoft Office application. Custom task panes give you a way to create your own task pane and provide users with a familiar interface to access your solution's features. For example, the interface can contain controls that run code to modify documents or display data from a data source. See Walkthrough: Automate an application from a custom task pane 快速入门。