How to Add a .NET Spreadsheet Ribbon Bar Control using C#
Tags: webdev, devops, dotnet, tutorial
Published: 2024-03-06 21:42:53

---
canonical_url: https://developer.mescius.com/blogs/how-to-add-net-spreadsheet-ribbon-bar-control-using-c-sharp
description: Learn how to add a .NET spreadsheet ribbon bar control to your desktop application using C#. See more from Spread.NET today.
---
**What You Will Need**
- Visual Studio (This example uses VS2022)
- .NET 8
- NuGet Package: [GrapeCity.Spread.WinForms](https://www.nuget.org/packages/GrapeCity.Spread.WinForms)

**Controls Referenced**
- [Spread.NET - .NET/C# Spreadsheet Component](https://developer.mescius.com/spreadnet)
- [Online Documentation](https://developer.mescius.com/spreadnet/docs) | [Demos](https://developer.mescius.com/spreadnet/demos)

**Tutorial Concept**
.NET C# Ribbon Control - Learn how to add an Excel-like toolbar ribbon to a .NET 8 WinForms application using C#.


---
During this piece, we will guide you through the simple process of integrating a spreadsheet Ribbon Bar control into a .NET 8 WinForms application. The control we will be using is [**<span>Spread.NET</span>**](https://developer.mescius.com/spreadnet "https://developer.mescius.com/spreadnet"), a .NET/C# spreadsheet component. Spread.NET enables developers to create feature-rich, Excel-like user interfaces with an extensible set of classes, all created to incorporate spreadsheet functionality into .NET applications.

Spread.NET for WinForms comes equipped with a built-in [**Ribbon Bar control**](https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-ribboncontrol.html "https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-ribboncontrol.html"), offering an Excel-like ribbon toolbar UI. This includes contextual behaviors, command execution, error handling, and full customization options that allow developers to easily and seamlessly offer a familiar look and feel directly from within their application interface. Let's get started!

### Steps to Add a Spreadsheet Ribbon Bar Control to a .NET 8 WinForms App using C#

1.  [<span>Create a WinForms .NET 8 App</span>](#create)
2.  [<span>Add a .NET Spreadsheet Component on the Form</span>](#add)
3.  [<span>Attach Ribbon Bar Control to .NET Spreadsheet Instance using C#</span>](#attach)
4.  [**<span>Bonus:</span>** Programmatically Customize the .NET Spreadsheet Ribbon Bar Control](#program)

[<span>Download a Sample App to Follow Along with the Piece.</span>](https://cdn.mescius.io/assets/developer/blogs/spread/20240206-How-to-Add-a-NET-Spreadsheet-Ribbon-Bar-Control-using-C/RibbonBarControl.zip)

### <a id="create"></a>Create a WinForms .NET 8 App

In **Visual Studio 2022**, create a new project and select **Windows Forms App (.NET Framework)** containing **C#** under it. Next, [<span>download</span>](https://developer.mescius.com/spreadnet/download "https://developer.mescius.com/spreadnet/download") the latest Spread.NET release and install it on your machine. [See our Quick Start documentation for more information on getting started](https://developer.mescius.com/spreadnet/docs/latest/online-win/adding-component-to-visual-studio-2019.html "https://developer.mescius.com/spreadnet/docs/latest/online-win/adding-component-to-visual-studio-2019.html").

Alternatively, Spread.NET is accessible via NuGet by searching for “MESCIUS Spread WinForms”, and selecting [**<span>GrapeCity.Spread.WinForms</span>**](https://www.nuget.org/packages/GrapeCity.Spread.WinForms "https://www.nuget.org/packages/GrapeCity.Spread.WinForms").

<span>![Create a WinForms .NET App](//cdn.mescius.io/umb/media/04wjvin1/01-ribbon.png?rmode=max&width=733&height=367)</span>

### <a id="add"></a>Add a .NET Spreadsheet Component on the Form

From the VS Toolbox, drag the **FpSpread** component and drop it onto the form. Adjust the spreadsheet as needed:

![Add .NET Spreadsheet to WinForms App](//cdn.mescius.io/umb/media/gi0o5vyf/add-net-spreadsheet-to-winforms-app.gif?rmode=max&width=754&height=377)

You have successfully added the Spread.NET component to the WinForms project.

### <a id="attach"></a>Attach Ribbon Bar Control to .NET Spreadsheet Instance

From the VS Toolbox, drag the **RibbonBar** component and drop it onto the form on top of the spreadsheet instance. In the **Form1.cs** file, add the following code to [<span>generate the default RibbonBar items and behaviors</span>](https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-ribboncontrol.html#i-heading-generate-ribbonbar-items-manually "https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-ribboncontrol.html#i-heading-generate-ribbonbar-items-manually")<span>,</span> and [attach the control to the Spreadsheet component](https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-ribboncontrol.html#i-heading-attach-ribbonbar-control "https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-ribboncontrol.html#i-heading-attach-ribbonbar-control"):

```
    using GrapeCity.Spreadsheet.WinForms.Ribbon;

    namespace RibbonBarControl
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                ribbonBar1.GenerateDefaultItems();
                // Attach ribbonBar control to FpSpread control
                ribbonBar1.Attach(fpSpread1);
            }
        }
    }
```

![Add Ribbon Bar C# .NET](//cdn.mescius.io/umb/media/soak3aqn/add-ribbon.gif?rmode=max&width=744&height=372)

Run the WinForms app and notice the Ribbon Bar control and the .NET Spreadsheet instance are working together, allowing the end user to easily import/export and modify Excel spreadsheets.

![Run App with Ribbon Bar and .NET Spreadsheet](//cdn.mescius.io/umb/media/yhwhgdxj/run-app-with-ribbon-bar-and-net-spreadsheet.gif?rmode=max&width=750&height=375)

### <a id="program"></a>Bonus: Programmatically Customize the .NET Spreadsheet Ribbon Bar Control

Spread.NET’s Ribbon Bar control supports customization through the API. The control itself consists of different tab items that perform a specified command or action. There are various types of group items available in a ribbonBar’s tab, such as toolbars, menus, tab items, icons, and so on. Developers can [add, remove, or modify the ribbonBar items](https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-ribboncontrol.html#i-heading-add-custom-items-to-ribbonbar "https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-ribboncontrol.html#i-heading-add-custom-items-to-ribbonbar") to meet the needs of their users.

The following code shows how to add a new tab along with a new tab group and group item.

```
    using GrapeCity.Spreadsheet.WinForms.Ribbon;

    namespace RibbonBarControl
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                ribbonBar1.GenerateDefaultItems();
                // Attach ribbonBar control to FpSpread control
                ribbonBar1.Attach(fpSpread1);
                // Add custom items on ribbonBar
                ribbonBar1.Attach(fpSpread1);
                ribbonBar1.Tabs.Add(new GrapeCity.Spreadsheet.WinForms.Ribbon.RibbonTab());
                ribbonBar1.Tabs[8].Text = "New Tab";
                ribbonBar1.Tabs[8].Groups.Add(new RibbonGroup());
                ribbonBar1.Tabs[8].Groups[0].Text = "New Group";
                ribbonBar1.Tabs[8].Groups[0].Items.Add("New Item");
                ribbonBar1.Tabs[8].Groups[0].Items[0].Name = "test";
                ribbonBar1.Tabs[8].Groups[0].Items["test"].CommandName = "Orientation";
                ribbonBar1.Tabs[8].Groups[0].Items["test"].CommandParameter = 30;
                ribbonBar1.Tabs[0].Groups[0].Items[0].Visible = false;
                ((RibbonButton)ribbonBar1.Tabs[1].Groups[0].Items[0]).Text = "New Name";
            }
        }
    }
```

![Customize Ribbon Bar #C .NET](//cdn.mescius.io/umb/media/3xndugyt/customzie.gif?rmode=max&width=756&height=378)

<div class="MsoNormal">

* * *

</div>

### Learn More About this .NET Spreadsheet Component

This article only scratches the surface of the full capabilities of [**Spread.NET**](https://developer.mescius.com/spreadnet "https://developer.mescius.com/spreadnet"), the .NET spreadsheet component. Review the [documentation](https://developer.mescius.com/spreadnet/docs "https://developer.mescius.com/spreadnet/docs") to see some of the many available features, and [download our demo explorer](https://developer.mescius.com/spreadnet/demos "https://developer.mescius.com/spreadnet/demos") to see the features in action and interact with the sample code. Integrating a spreadsheet component into your applications allows you to customize your users' experience and provide them with familiar spreadsheet functionality without referring them to an external program. To learn more about Spread.NET and the new features added in the latest release, check out our [release pages](https://developer.mescius.com/spreadnet/releases "https://developer.mescius.com/spreadnet/releases").