Microsoft.Office.Interop.Excel将单选按钮添加到工作表

时间:2015-06-15 22:22:25

标签: c# excel

我一直在寻找有关如何以编程方式将单选按钮添加到Excel工作表的示例,但无法得到直接答案。我尝试过使用Microsoft.Office.Interop.Excel和Microsoft.Office.Tools.Excel,但都没有用过。我正在使用的系统已经将Microsoft.Office.Interop.Excel作为参考,所以除非对使用这个程序集有任何异议,否则这将是我的偏好。

//propertyWorkSheet is a Microsoft.Office.Interop.Excel worksheet
Microsoft.Office.Tools.Excel.Application xlApp = new Excel.Application();
Microsoft.Office.Tools.Excel.Worksheet worksheet = (Microsoft.Office.Tools.Excel.Worksheet)propertyWorksheet;

Microsoft.Office.Tools.Excel.Range selection = worksheet.get_Range("A12:A12", "A12:A12");

Microsoft.Office.Tools.Excel.Controls.Button button = new Microsoft.Office.Tools.Excel.Controls.Button();
worksheet.Controls.AddControl(button, selection, "Button");

1 个答案:

答案 0 :(得分:1)

进行了更多挖掘,并使用我的代码完成了这项工作。

    Microsoft.Office.Interop.Excel.Buttons buttons = propertyWorksheet.Buttons(System.Reflection.Missing.Value) as Microsoft.Office.Interop.Excel.Buttons;
    Microsoft.Office.Interop.Excel.Button button = buttons.Add(33, 33, 33, 33);
    button.Caption = "Test BUTTON";