AudioDev
AudioDev

Reputation: 270

Microsoft.Office.Interop.Excel add radio button to worksheet

I keep looking for examples on how to add a radio button to an Excel worksheet programmatically but cannot get a straight answer. I've tried using Microsoft.Office.Interop.Excel and Microsoft.Office.Tools.Excel but neither have worked. The system I am working on already has Microsoft.Office.Interop.Excel as a reference so unless there are any objections to using this assembly, this would be my preference.

//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");

Upvotes: 1

Views: 996

Answers (1)

AudioDev
AudioDev

Reputation: 270

Did some more digging and got to this with my code and it worked.

    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";

Upvotes: 1

Related Questions