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.

Excel with form controls created with GemBox.Spreadsheet
Screenshot of Excel with form controls created with GemBox.Spreadsheet
using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If using 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 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

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.