我想在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