Excel Form Controls in C# and VB.NET
With GemBox.Spreadsheet you can work with spreadsheets that contain form controls such as check boxes, radio (option) buttons, combo boxes, buttons, list boxes, spin buttons, scroll bars, labels, or group boxes.
The following example shows how to create a workbook with some of the most common form controls.

using GemBox.Spreadsheet;
class Program
{
static void Main()
{
// If using the Professional version, put your serial key below.
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
var workbook = new ExcelFile();
var worksheet = workbook.Worksheets.Add("Form Controls");
var checkBox = worksheet.FormControls.AddCheckBox("Simple check box", "B2", 100, 15, LengthUnit.Point);
checkBox.CellLink = worksheet.Cells["A2"];
checkBox.Checked = true;
worksheet.Cells["A4"].Value = "VALUE A";
worksheet.Cells["A5"].Value = "VALUE B";
worksheet.Cells["A6"].Value = "VALUE C";
worksheet.Cells["A7"].Value = "VALUE D";
var comboBox = worksheet.FormControls.AddComboBox("B4", 100, 20, LengthUnit.Point);
comboBox.InputRange = worksheet.Cells.GetSubrange("A4:A7");
comboBox.SelectedIndex = 2;
var scrollBar = worksheet.FormControls.AddScrollBar("B9", 100, 20, LengthUnit.Point);
scrollBar.CellLink = worksheet.Cells["A9"];
scrollBar.MinimumValue = 10;
scrollBar.MaximumValue = 50;
scrollBar.CurrentValue = 20;
workbook.Save("Form Controls.xlsx");
}
}
Imports GemBox.Spreadsheet
Module Program
Sub Main()
' If using the Professional version, put your serial key below.
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
Dim workbook As New ExcelFile()
Dim worksheet = workbook.Worksheets.Add("Form Controls")
Dim checkBox = worksheet.FormControls.AddCheckBox("Simple check box", "B2", 100, 15, LengthUnit.Point)
checkBox.CellLink = worksheet.Cells("A2")
checkBox.Checked = True
worksheet.Cells("A4").Value = "VALUE A"
worksheet.Cells("A5").Value = "VALUE B"
worksheet.Cells("A6").Value = "VALUE C"
worksheet.Cells("A7").Value = "VALUE D"
Dim comboBox = worksheet.FormControls.AddComboBox("B4", 100, 20, LengthUnit.Point)
comboBox.InputRange = worksheet.Cells.GetSubrange("A4:A7")
comboBox.SelectedIndex = 2
Dim scrollBar = worksheet.FormControls.AddScrollBar("B9", 100, 20, LengthUnit.Point)
scrollBar.CellLink = worksheet.Cells("A9")
scrollBar.MinimumValue = 10
scrollBar.MaximumValue = 50
scrollBar.CurrentValue = 20
workbook.Save("Form Controls.xlsx")
End Sub
End Module
See also
Next steps
Published: May 10, 2021 | Modified: December 19, 2022 | Author: Marek Turis