Excel 加载项按钮

本文关键字:按钮 加载项 Excel | 更新日期: 2023-09-27 18:36:57

我是 Excel 插件编程的新手。我在 C# 中为 Excel 2010 创建了一个 Excel 插件,它将在每张工作簿中创建按钮。

有人可以告诉我这段代码有什么问题:

Excel.Worksheet activeWorksheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;
Microsoft.Office.Tools.Excel.Worksheet vstoWorksheet = activeWorksheet.GetVstoObject(Globals.Factory);
Excel.Range selection = vstoWorksheet.Range[2, 2];
Microsoft.Office.Tools.Excel.Controls.Button button = new Microsoft.Office.Tools.Excel.Controls.Button();
button.Tag = vstoWorksheet.Controls.AddControl(button,selection, "Click"); button.Name = "Click";
button.BackColor = System.Drawing.Color.Cyan;
button.Text = "Click";

Excel 加载项按钮

我看到了问题:

button.Tag = vstoWorksheet.Controls.AddControl(button,selection, "Click"); 

应该是:

vstoWorksheet.Controls.AddControl(button,selection, "Click");