1

我是 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";
4

1 回答 1

0

我看到了问题:

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

应该:

vstoWorksheet.Controls.AddControl(button,selection, "Click"); 
于 2012-08-23T01:37:15.383 回答