Quick Start Guide | |
---|---|
What You Will Need |
Visual Studio (This example uses VS2022) .NET 8 NuGet Package: |
Controls Referenced | |
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 Spread.NET, 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, 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#
- Create a WinForms .NET 8 App
- Add a .NET Spreadsheet Component on the Form
- Attach Ribbon Bar Control to .NET Spreadsheet Instance using C#
- Bonus: Programmatically Customize the .NET Spreadsheet Ribbon Bar Control
Download a Sample App to Follow Along with the Piece.
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, download the latest Spread.NET release and install it on your machine. See our Quick Start documentation for more information on getting started.
Download a Trial for this .NET Spreadsheet Today!
Alternatively, Spread.NET is accessible via NuGet by searching for “MESCIUS Spread WinForms”, and selecting GrapeCity.Spread.WinForms.
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:
You have successfully added the Spread.NET component to the WinForms project.
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 generate the default RibbonBar items and behaviors, and attach the control to the Spreadsheet component:
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);
}
}
}
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.
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 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";
}
}
}
Learn More About this .NET Spreadsheet Component
This article only scratches the surface of the full capabilities of Spread.NET, the .NET spreadsheet component. Review the documentation to see some of the many available features, and download our demo explorer 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.
Ready to Get Started? Download a Trial for this .NET Spreadsheet Today!