DEV Community

Cover image for Create Interactive Excel Forms in C# Using .NET Excel Library
Phinter Atieno for Syncfusion, Inc.

Posted on • Originally published at syncfusion.com on

Create Interactive Excel Forms in C# Using .NET Excel Library

TL;DR: Quickly learn how to build interactive Excel forms in C# using a powerful Excel library. This guide covers adding form controls like text boxes and combo boxes, linking them to named ranges, validating input, and exporting responses; all automated with .NET.

Excel is more than just a spreadsheet tool; it can be a powerful platform for building interactive data collection forms. Whether you’re gathering support tickets, customer feedback, or internal reports, automating form creation in Excel can save time and reduce manual errors.

In this blog, you’ll learn how to build a fully functional support ticket intake form in Excel using Syncfusion XlsIO. We’ll walk through adding form controls like text boxes, combo boxes, and checkboxes, apply data validation, and export responses, all from a .NET console application.

Why use Syncfusion .NET Excel Library?

Syncfusion’s Essential XlsIO is a robust .NET Excel Library that enables developers to create, read, and edit Excel documents programmatically. It supports:

  • Form controls and data validation
  • Excel formulas and conditional formatting
  • Charts, tables, pivot tables, and sparklines
  • Export to PDF, CSV, JSON, and more

For form-building scenarios, it also offers native support for interactive UI elements directly within Excel.

Benefits of Excel forms

Excel forms offer a seamless way to collect structured data offline, combining the familiarity of spreadsheets with the power of interactive controls and automation.

Key benefits include:

  • Offline processing of sensitive data
  • Intuitive UI for data entry
  • Data consistency via named ranges and validations
  • Automation with C# for reading/writing control values
  • No need for external tools or web interfaces

Let’s build a support ticket intake form using Syncfusion’s .NET Excel library with built-in controls.

Prerequisites

To follow along, ensure you have:

Steps to build a data collection form

Step 1: Create a .NET application

Start by creating a new .NET Core console application in Visual Studio.

Step 2: Install the NuGet packages

Install the Syncfusion.XlsIO.NET.Core package from NuGet.org.

Step 3: Create worksheet

Once the package is installed, initialize an Excel engine and create two sheets, one for the form and one for lookup data.

Private static void CreateExcelFormWithControls(string filePath)
{
    // Initialize Excel Engine
    using (ExcelEngine engine = new ExcelEngine())
    {
        // Access Excel application
        Iapplication application = engine.Excel;

        // Set the default Excel version
        application.DefaultVersion = ExcelVersion.Xlsx;

        // Create workbook with two worksheets
        Iworkbook workbook = application.Workbooks.Create(2);
        Iworksheet formSheet = workbook.Worksheets[0];

        // Set worksheet name
        formSheet.Name = Form;

        // Access lookup worksheet and set name
        Iworksheet lookupSheet = workbook.Worksheets[1];
        lookupSheet.Name = Lookups;

        // Create lookup references for form
        BuildLookupsAndNames(workbook, lookupSheet);

        // Create Excel form
        BuildFormLayout(formSheet);

        // Save the Form as an Excel workbook
        workbook.SaveAs(SupportTicketForm.xlsx);
    }
}
Enter fullscreen mode Exit fullscreen mode

Step 4: Add lookup references

Populate the lookup sheet with reference data such as channels, categories, and priorities. Then, define named ranges for use in the form.

private static void BuildLookupsAndNames(IWorkbook workbook, IWorksheet lookupSheet)
{
    // Add lookup values
    // Set Titles
    lookupSheet.Range["A1"].Text = "Channels";
    lookupSheet.Range["B1"].Text = "Categories";
    lookupSheet.Range["C1"].Text = "Priorities";

    .....
    .....

    // Create named ranges
    Workbook.Names.Add("Channels").RefersToRange = lookupSheet.Range["A2:A5"];
    ....
    ....

    // Autofit the columns
    lookupSheet.UsedRange.AutofitColumns();

    // Protect the Excel worksheet
    lookupSheet.Protect("ProtectLookUp");
}
Enter fullscreen mode Exit fullscreen mode

Step 5: Create form labels

Design the form layout with labels, formatting, and guidance for users. Include required fields and apply styling for clarity.

private static void BuildFormLayout(IWorksheet formSheet)
{
    // Create Form Titles    
    formSheet.Range["B2"].Text = "Support Ticket Intake";
    formSheet.Range["B2"].CellStyle.Font.Bold = true;
    formSheet.Range["B2"].CellStyle.Font.Size = 18;
    formSheet.Range["B2"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
    formSheet.Range["B2:F2"].Merge();

    formSheet.Range["B3:F3"].Merge();
    formSheet.Range["B3"].Text = "Fill the form using the controls. Required fields marked *.";
    formSheet.Range["B3"].CellStyle.Font.Italic = true;
    formSheet.Range["B3"].CellStyle.Font.Color = ExcelKnownColors.Indigo;

    // Set the required form details
    formSheet.Range[$"B5"].Text = "Ticket Date *";
    formSheet.Range[$"B9"].Text = "Customer Name *";
    formSheet.Range[$"B13"].Text = "Email *";
    formSheet.Range[$"B17"].Text = "Phone";
    formSheet.Range[$"B21"].Text = "Channel *";
    formSheet.Range[$"B25"].Text = "Category *";
    formSheet.Range[$"B29"].Text = "Priority *";
    formSheet.Range[$"B33"].Text = "Requires Follow-up";
    formSheet.Range[$"B37"].Text = "Issue Summary *";
    formSheet.Range[$"B41"].Text = "Details";

    formSheet.SetColumnWidth(2,28); // B
    formSheet.Range["B1:B41"].CellStyle.Font.Bold = true;
    formSheet.Range["B1:B41"].CellStyle.Font.Size = 14;
    formSheet.SetColumnWidth(4, 40);

    // Set Number Format
    formSheet.Range["D5"].NumberFormat = "dd-mmm-yyyy";
    formSheet.Range["D5"].BorderAround();

    // Add data validation for date
    IDataValidation dataValidation = formSheet.Range["D5"].DataValidation;
    dataValidation.AllowType = ExcelDataType.Date;
    dataValidation.CompareOperator = ExcelDataValidationComparisonOperator.GreaterOrEqual;
    dataValidation.FirstDateTime = new DateTime(2000, 1, 1);
    dataValidation.ErrorBoxText = "Enter a valid date on or after 01-Jan-2000.";

    // Add Form controls
    AddFormControlsAndLinking(formSheet);
}
Enter fullscreen mode Exit fullscreen mode

Step 6: Add form control shapes

Insert text boxes, combo boxes, option buttons, and checkboxes to make the form interactive.

private static void AddFormControlsAndLinking(IWorksheet form)
{
    // Add customer name text box
    ITextBoxShape nameTextBox = form.Shapes.AddTextBox();
    nameTextBox.Left = 330;
    nameTextBox.Top = 200;
    nameTextBox.Height = 30;
    nameTextBox.Width = 280;
    nameTextBox.Name = "CustomerNameTextBox";

    // Add email address text box
    ITextBoxShape emailTxtBox = form.Shapes.AddTextBox();
    emailTxtBox.Left = 330;
    emailTxtBox.Top = 300;
    emailTxtBox.Height = 30;
    emailTxtBox.Width = 280;
    emailTxtBox.Name = "EmailTextBox";

    // Add text box for phone number
    ITextBoxShape phoneTxtBox = form.Shapes.AddTextBox();
    phoneTxtBox.Left = 330;
    phoneTxtBox.Top = 400;
    phoneTxtBox.Height = 30;
    phoneTxtBox.Width = 280;
    phoneTxtBox.Name = "PhoneTextBox";

    // Add combo box for channels
    IComboBoxShape channelComboBox = form.Shapes.AddComboBox();
    channelComboBox.Left = 330;
    channelComboBox.Top = 500;
    channelComboBox.Height = 30;
    channelComboBox.Width = 280;
    channelComboBox.ListFillRange = form.Workbook.Names["Channels"].RefersToRange;
    channelComboBox.LinkedCell = form["G9"]; 
    channelComboBox.DropDownLines = 6;
    form.Range["H9"].Formula = "=IF(G9>0, INDEX(Channels, G9), \"\")";
    form.Range["G9:H9"].CellStyle.Font.Color = ExcelKnownColors.White;
    form.Workbook.Names.Add("SelectedChannel").RefersToRange = form.Range["H9"];
    channelComboBox.Name = "ChannelComboBox";

    // Add combo box for categories
    IComboBoxShape categoryComboBox = form.Shapes.AddComboBox();
    categoryComboBox.Left = 330;
    categoryComboBox.Top = 600;
    categoryComboBox.Height = 30;
    categoryComboBox.Width = 280;
    categoryComboBox.ListFillRange = form.Workbook.Names["CategoryList"].RefersToRange;
    categoryComboBox.LinkedCell = form["G10"];
    categoryComboBox.DropDownLines = 6;
    form.Range["H10"].Formula = "=IF(AND(G10>0,COUNTA(CategoryList)>0), INDEX(CategoryList, G10), \"\")";
    form.Range["G10:H10"].CellStyle.Font.Color = ExcelKnownColors.White;
    categoryComboBox.Name = "CategoryComboBox";

    // Add priority option buttons
    IOptionButtonShape optLow = form.OptionButtons.AddOptionButton();
    optLow.Left = 330;
    optLow.Top = 700;
    optLow.Height = 30;
    optLow.Width = 150;
    optLow.Text = "Low";
    optLow.Name = "Priority";

    IOptionButtonShape optMedium = form.OptionButtons.AddOptionButton();
    optMedium.Left = 480;
    optMedium.Top = 700;
    optMedium.Height = 30;
    optMedium.Width = 150;
    optMedium.Text = "Medium";
    optMedium.Name = "Priority";

    IOptionButtonShape optHigh = form.OptionButtons.AddOptionButton();
    optHigh.Left = 630;
    optHigh.Top = 700;
    optHigh.Height = 30;
    optHigh.Width = 150;
    optHigh.Text = "High";
    optHigh.Name = "Priority";

    IOptionButtonShape optCritical = form.OptionButtons.AddOptionButton();
    optCritical.Left = 780;
    optCritical.Top = 700;
    optCritical.Height = 30;
    optCritical.Width = 150;
    optCritical.Text = "Critical";
    optCritical.LinkedCell = form["G11"];
    optCritical.Name = "Priority";
    optMedium.CheckState = ExcelCheckState.Checked;
    form.Range["H11"].Formula = "=IF(G11>0, INDEX(Priorities, G11), \"\")";
    form.Range["G11:H11"].CellStyle.Font.Color = ExcelKnownColors.White;

    // Add a checkbox for follow-up
    ICheckBoxShape followCb = form.Shapes.AddCheckBox();
    followCb.Left = 330;
    followCb.Top = 800;
    followCb.Height = 30;
    followCb.Width = 200;
    followCb.LinkedCell = form["G12"];
    followCb.Text = "Requires Follow-up";
    followCb.CheckState = ExcelCheckState.Unchecked;
    followCb.Line.ForeColor = Color.White;
    form.Range["H12"].Formula = "=IF(G12, \"Yes\", \"No\")";
    form.Range["G12:H12"].CellStyle.Font.Color = ExcelKnownColors.White;
    followCb.Name = "FollowUpCheckBox";

    // Add summary text box
    ITextBoxShape summaryTb = form.Shapes.AddTextBox();
    summaryTb.Left = 330;
    summaryTb.Top = 900;
    summaryTb.Height = 30;
    summaryTb.Width = 320;
    summaryTb.Name = "IssueSummaryTextBox";

    // Add details text box
    ITextBoxShape detailsTb = form.Shapes.AddTextBox();
    detailsTb.Left = 330;
    detailsTb.Top = 1000;
    detailsTb.Height = 100;
    detailsTb.Width = 320;
    detailsTb.Name = "DetailsTextBox";

    // Hide the gridlines
    form.IsGridLinesVisible = false;
}
Enter fullscreen mode Exit fullscreen mode

We have created a support ticket intake form to gather the details of your support query. Here’s how the form looks after rendering.

Support ticket intake form


Support ticket intake form

The Excel form will appear as shown below when entering the form details.

Excel form after filling in data


Excel form after filling in data

Exporting form data to Excel

Once a form is filled out, you can export the data to a structured Excel sheet using Syncfusion’s .NET Excel Library.

Below is a breakdown of the process:

1. Read and Export Excel Form Data

This method initializes the Excel engine, creates a workbook, builds a response table, reads form data, and saves the file.

Private static void ReadExcelForms(string form)
{
    // Initialize Excel Engine
    using (ExcelEngine engine = new ExcelEngine())
    {
        // Access Excel application
        Iapplication application = engine.Excel;

        // Set the default Excel version
        application.DefaultVersion = ExcelVersion.Xlsx;

        // Create Excel workbook
        Iworkbook workbook = application.Workbooks.Create(1);
        Iworksheet responseSheet = workbook.Worksheets[0];

        // Set sheet name
        responseSheet.Name = "Responses";

        // Create response table
        BuildResponsesTable(responseSheet);

        // Read Excel form
        ReadResponses(form, responsesSheet);

        // Save the workbook
        workbook.SaveAs(SupportTicketResponses.xlsx);
    }
}
Enter fullscreen mode Exit fullscreen mode

2. Build the Response Table

This method sets up the headers and formatting for the response sheet.

private static void BuildResponsesTable(IWorksheet worksheet)
{
    // Set the required form categories
    worksheet.Range["A1"].Text = "Ticket ID";
    worksheet.Range["B1"].Text = "CreatedOn";
    worksheet.Range["C1"].Text = "TicketDate";
    worksheet.Range["D1"].Text = "CustomerName";
    worksheet.Range["E1"].Text = "Email";
    worksheet.Range["F1"].Text = "Phone";
    worksheet.Range["G1"].Text = "Channel";
    worksheet.Range["H1"].Text = "Category";
    worksheet.Range["I1"].Text = "Priority";
    worksheet.Range["J1"].Text = "RequiresFollowUp";
    worksheet.Range["K1"].Text = "IssueSummary";
    worksheet.Range["L1"].Text = "Details";

    // Create a table
    var table = worksheet.ListObjects.Create("ResponsesTable", worksheet.Range["A1:L1"]);
    table.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium9;
    worksheet.UsedRange.AutofitColumns();
}
Enter fullscreen mode Exit fullscreen mode

3. Read Responses from the Form

This method extracts values from form controls and populates the response sheet.

private static void ReadResponses(string form, IWorksheet responseSheet)
{
    // Initialize Excel Engine
    using (ExcelEngine engine = new ExcelEngine())
    {
        // Access Excel application
        IApplication application = engine.Excel;

        // Set the default Excel version
        application.DefaultVersion = ExcelVersion.Xlsx;

        // Open the Excel form
        IWorkbook formWb = application.Workbooks.Open(form);
        IWorksheet formSheet = formWb.Worksheets[0];

        // Access last row of the table
        int lastRow = responseSheet.ListObjects[0].Location.LastRow;
        responseSheet.InsertRow(lastRow + 1);
        int newRow = lastRow;

        // Set ticket id
        responseSheet.Range[$"A{newRow}"].Number = newRow - 1; 

        // Set Response created date
        responseSheet.Range[$"B{newRow}"].DateTime = DateTime.Now; 

        // Set Ticket created date
        responseSheet.Range[$"C{newRow}"].DateTime = formSheet.Range["D5"].DateTime; 

        // Set customer name
        responseSheet.Range[$"D{newRow}"].Text = formSheet.TextBoxes["CustomerNameTextBox"].Text; 

        // Set Email address
        responseSheet.Range[$"E{newRow}"].Text = formSheet.TextBoxes["EmailTextBox"].Text; 

        // Set Phone number
        responseSheet.Range[$"F{newRow}"].Text = formSheet.TextBoxes["PhoneTextBox"].Text;

        // Set communicated channel
        responseSheet.Range[$"G{newRow}"].Text = formSheet.ComboBoxes[0].SelectedValue; 

        // Set Category
        responseSheet.Range[$"H{newRow}"].Text = formSheet.ComboBoxes[1].SelectedValue; 

        // Set Priority
        responseSheet.Range[$"I{newRow}"].Text = formSheet.OptionButtons["Priority"].LinkedCell.Text; 

        // Set whether follow-up up needed.
        responseSheet.Range[$"J{newRow}"].Text = formSheet.CheckBoxes["FollowUpCheckBox"].CheckState == ExcelCheckState.Checked ? "Needed":"No Need"; // RequiresFollowUp

        // Set ticket summary
        responseSheet.Range[$"K{newRow}"].Text = formSheet.TextBoxes["IssueSummaryTextBox"].Text; 

        // Set details
        responseSheet.Range[$"L{newRow}"].Text = formSheet.TextBoxes["DetailsTextBox"].Text; 

        responseSheet.UsedRange.AutofitColumns();
    }
}
Enter fullscreen mode Exit fullscreen mode

When the form data is exported to Excel, it appears as shown below.

Exported form data table


Exported form data table

Other use cases

This approach can be adapted for various scenarios, such as:

  • Employee feedback forms: Collect internal feedback for HR analysis.
  • Customer satisfaction surveys: Automate survey creation and export responses.
  • Product issue reporting: Enable QA teams to log bugs directly into Excel.
  • Event registration forms: Gather attendee details and preferences.

GitHub reference

You can download the complete samples from GitHub.

Conclusion

Using Syncfusion Excel Library (XlsIO), you can build compact, interactive forms in Excel using C#. This approach is ideal for offline data collection, automation, and structured reporting.

If you are new to our .NET Excel Library, we highly recommend following our Getting Started guide. Using the library, you can also export or write Excel data to PDF, images, data tables, HTML, CSV, TSV, collections of objects, ODS, and JSON. For more insights, please refer to our online demos.

If you’re a Syncfusion user, you can download the setup from the license and downloads page. Otherwise, you can download a free 30-day trial.

You can also contact us through our support forum, support portal, or Feedback Portal for queries. We are always happy to assist you!

Related Blogs

This article was originally published at Syncfusion.com.

Top comments (0)