Getting Started with Windows Forms Spreadsheet

29 May 20234 minutes to read

This section helps you to get started with the Spreadsheet

Assemblies deployment

Below table describes, list of assemblies required to be added in project when the WinForms Spreadsheet control is used in your application.

Assembly Description
Syncfusion.Spreadsheet.Windows.dll Contains the classes that handles all the UI Operations of Spreadsheet such as importing of sheets, applying formulas/styles etc.
Syncfusion.Shared.Base.dll Contains the classes which holds the controls like TabBarPage, TabBarSplitterControl etc.
Syncfusion.Tools.Windows.dll Contains the classes which holds the controls like Ribbon, ToolStripPanelItem,MaskedEditBox,ToolStripGallery,BackStageButton etc which are used in Spreadsheet.
Syncfusion.XlsIO.Base.dll Contains the base classes which is responsible for read and write in Excel files, Worksheet Manipulations, Formula calculations etc.

Below are the assemblies list that can be added when you want to enable certain features in Spreadsheet control.

Optional Assemblies Description
Syncfusion.SpreadsheetHelper.Windows.dll Contains the classes which is responsible for importing charts and sparklines into Spreadsheet
Syncfusion.ExcelChartToImageConverter.WPF.dll Contains the classes which is responsible for converting charts as image
Syncfusion.Chart.Base.dll Contains the base classes which is responsible for importing charts like Line charts, Pie charts, Sparklines etc.
Syncfusion.Chart.Windows.dll Contains the classes which is responsible for creating charts that holds axes, series, legends etc.
Syncfusion.ExcelToPDFConverter.Base.dll Contains the base and fundamental classes which is responsible for converting excel to PDF.
Syncfusion.Pdf.Base.dll Contains the base and fundamental classes for creating PDF.

Create a simple application with Spreadsheet

WinForms Spreadsheet control can be added into the application either via designer or via coding.

Adding a control via designer

1.Create new Windows Forms application in Visual Studio.

2.Open the Visual Studio Tool box. Navigate to Syncfusion Controls tab, and find the Spreadsheet/SpreadsheetRibbon toolbox items

Toolbox in WindowsForms Spreadsheet

3.Drag Spreadsheet and drop in the Designer area from the Toolbox

4.Ribbon can be added to the application by dragging SpreadsheetRibbon to the Designer area.

5.To make an interaction between Ribbon items and Spreadsheet, bind the Spreadsheet as DataContext to the SpreadsheetRibbon.

Adding control via coding

Spreadsheet is available in the following namespace Syncfusion.Windows.Forms.Spreadsheet and it can be created programmatically by using below code.

For Spreadsheet

private Spreadsheet spreadsheet;
spreadsheet = new Spreadsheet();
SpreadsheetRibbon ribbon = new SpreadsheetRibbon() { Spreadsheet = spreadsheet };
spreadsheet.Dock = DockStyle.Fill;
spreadsheet.Anchor = AnchorStyles.Left | AnchorStyles.Top;
          
this.Controls.Add(spreadsheet);
this.Controls.Add(ribbon);

You can get the following output when execute the application.

Adding control via coding in WindowsForms Spreadsheet

Creating a new Excel Workbook

A new workbook can be created by using a Create method with specified number of worksheets. By default, a workbook will be created with single worksheet.

spreadsheet.Create(2);

Opening an existing Excel Workbook

The Excel Workbook can be opened in Spreadsheet using the Open method in various ways,

//Using Stream,
spreadsheet.Open (Stream file);

//Using String,
spreadsheet.Open (string file);

//Using Workbook,
spreadsheet.Open(IWorkbook workbook);
spreadsheet.Open (@"..\..\Data\Outline.xlsx");

Opening an existing excel workbook in WindowsForms Spreadsheet

Opening Excel File in Spreadsheet

Saving the Excel Workbook

The Excel workbook can be saved in Spreadsheet using Save method. If the workbook already exists in the system drive, it will be saved in the same location, otherwise Save Dialog box opens to save the workbook in user specified location.

spreadsheet.Save();

You can also use SaveAs method directly to save the existing excel file with modifications.

The SaveAs method in Spreadsheet can be used in various ways,

//Using Stream,
spreadsheet.SaveAs (Stream file);

//Using String,
spreadsheet.SaveAs (string file);

//For Dialog box,
spreadsheet.SaveAs();

Displaying charts and sparklines

For importing charts and sparklines in Spreadsheet, add the following assembly as reference into the application.

Assembly: Syncfusion.SpreadsheetHelper.Windows.dll

Charts

Create an instance of Syncfusion.Windows.Forms.SpreadsheetHelper.GraphicChartCellRenderer and add that renderer into GraphicCellRenderers collection by using the helper method AddGraphicChartCellRenderer which is available under the namespace Syncfusion.Windows.Forms.Spreadsheet.GraphicCells.

public Form1()
{
    InitializeComponent();
  
    //For importing charts,
    this.spreadsheet.AddGraphicChartCellRenderer(new GraphicChartCellRenderer());
}

Sparklines

Create an instance of Syncfusion.Windows.Forms.SpreadsheetHelper.SparklineCellRenderer and add that renderer into Spreadsheet by using the helper method AddSparklineCellRenderer which is available under the namespace Syncfusion.Windows.Forms.Spreadsheet.GraphicCells.

public Form1()
{
    InitializeComponent();
      
    //For importing sparklines,
    this.spreadsheet.AddSparklineCellRenderer(new SparklineCellRenderer());
}

NOTE

You can refer to our WinForms Spreadsheet control feature tour page for its groundbreaking feature representations. You can also explore our WinForms Spreadsheet example that shows you how to render and configure the Spreadsheet.