我想在excel工作表上添加一个按钮。 根据互联网的例子,我试图做下面的代码。c#excel在excel工作表上创建一个按钮
using Excel = Microsoft.Office.Interop.Excel;
using VBIDE = Microsoft.Vbe.Interop;
private static void excelAddButtonWithVBA()
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlBook = xlApp.Workbooks.Open(@"PATH_TO_EXCEL_FILE");
Excel.Worksheet wrkSheet = xlBook.Worksheets[1];
Excel.Range range;
try
{
//set range for insert cell
range = wrkSheet.get_Range("A1:A1");
//insert the dropdown into the cell
Excel.Buttons xlButtons = wrkSheet.Buttons();
Excel.Button xlButton = xlButtons.Add((double)range.Left, (double)range.Top, (double)range.Width, (double)range.Height);
//set the name of the new button
xlButton.Name = "btnDoSomething";
xlButton.Text = "Click me!";
xlButton.OnAction = "btnDoSomething_Click";
buttonMacro(xlButton.Name, xlApp, xlBook, wrkSheet);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
xlApp.Visible = true;
}
但它口口声声说Excel不包含按钮 我应该包括使用按钮属性
预先感谢什么参考。
wrkSheet.Buttons();你可以试试wrkSheet.Buttons; ? – Eric 2014-11-03 08:24:48
工作表没有按钮功能。要使用工作表按钮,我需要包含哪些参考? – user3289230 2014-11-04 12:12:28