Skip to content
Open
8 changes: 6 additions & 2 deletions Document-Processing-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -5829,9 +5829,13 @@
<li>
<a href="/document-processing/excel/spreadsheet/winforms/overview">Windows Forms</a>
<ul>
<li><a href="/document-processing/excel/spreadsheet/winforms/overview">Overview</a></li>
<li><a href="/document-processing/excel/spreadsheet/winforms/getting-started">Getting Started</a></li>
<li><a href="/document-processing/excel/spreadsheet/winforms/working-with-spreadsheet">Working With Spreadsheet</a></li>
<li>
<a href="/document-processing/excel/spreadsheet/winforms/working-with-spreadsheet">Working With Spreadsheet</a>
<ul>
<li><a href="/document-processing/excel/spreadsheet/winforms/Workbook-Operations">Workbook Operations</a></li>
</ul>
</li>
<li><a href="/document-processing/excel/spreadsheet/winforms/selection">Selection</a></li>
<li><a href="/document-processing/excel/spreadsheet/winforms/editing">Editing</a></li>
<li><a href="/document-processing/excel/spreadsheet/winforms/formatting">Formatting</a></li>
Expand Down
233 changes: 106 additions & 127 deletions Document-Processing/Excel/Spreadsheet/Winforms/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,34 @@ documentation: ug
---

# Getting Started with Windows Forms Spreadsheet
This section briefly explains how to include the [Syncfusion<sup>®</sup> WinForms Spreadsheet](https://www.syncfusion.com/spreadsheet-editor-sdk/winforms-spreadsheet-editor) component in Windows Forms App using Visual Studio.

This section helps you to get started with the Spreadsheet
## Prerequisites
* [System requirements for WinForms components](https://help.syncfusion.com/windowsforms/system-requirements)

## Assemblies deployment
## Create a new Windows Forms App in Visual Studio

You can create a **Windows Forms Application** using Visual Studio via [Microsoft Templates](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/get-started/create-app-visual-studio) or the [Syncfusion<sup style="font-size:70%">&reg;</sup> Windows Forms](https://help.syncfusion.com/windowsforms/visual-studio-integration/template-studio).

## Assemblies Deployment

To add a WinForms spreadsheet component to your application by installing it via NuGet packages(Recommended) or by manually adding the required assemblies to the project.

{% tabcontents %}

{% tabcontent NuGet Package %}

### Install Syncfusion<sup style="font-size:70%">&reg;</sup> Windows Forms Spreadsheet NuGet packages

To add **Windows Forms Spreadsheet** component in the application, open the NuGet package manager in Visual Studio (*Tools → NuGet Package Manager → Manage NuGet Packages for Solution*), search and install:

• [Syncfusion.Spreadsheet.Windows](https://www.nuget.org/packages/Syncfusion.Spreadsheet.Windows)

{% endtabcontent %}

{% tabcontent Assemblies(.dll) %}

### Add Syncfusion® WinForms Spreadsheet Assemblies

Below table describes, list of assemblies required to be added in project when the [WinForms Spreadsheet](https://www.syncfusion.com/winforms-ui-controls/spreadsheet) control is used in your application.

Expand Down Expand Up @@ -70,167 +94,122 @@ Syncfusion.Pdf.Base.dll</td><td>
Contains the base and fundamental classes for creating PDF.</td></tr>
</table>

## Create a simple application with Spreadsheet
{% endtabcontent %}

{% endtabcontents %}

WinForms Spreadsheet control can be added into the application either via designer or via coding.
## Add Windows Forms Spreadsheet component

### Adding a control via designer
WinForms Spreadsheet control can be added to an application either through the designer (XAML) or programmatically using code.

1.Create new Windows Forms application in Visual Studio.
{% tabcontents %}

{% tabcontent Via Designer %}

2.Open the Visual Studio **Tool** **box**. Navigate to Syncfusion<sup>®</sup> Controls tab, and find the Spreadsheet/SpreadsheetRibbon toolbox items
1.Open the Visual Studio **Tool** **box**. Navigate to Syncfusion<sup>®</sup> Controls tab, and find the Spreadsheet/SpreadsheetRibbon toolbox items.

![Toolbox in WindowsForms Spreadsheet](getting-started_images/windowsforms-spreadsheet-toolbox.jpg)

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_
2.Drag `Spreadsheet` and drop in the Designer area from the Toolbox.

{% tabs %}

{% highlight c# %}

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);

{% highlight c# tabtitle="Form1.Designer.cs" %}
....
public Form1()
{
....
private void InitializeComponent()
{
Spreadsheet spreadsheet = new Spreadsheet();
}
....
}
....
{% endhighlight %}

{% endtabs %}

_You_ _can_ _get_ _the_ _following_ _output_ _when_ _execute_ _the_ _application_.

![Adding control via coding in WindowsForms Spreadsheet](getting-started_images/windowsforms-spreadsheet-coding.png)

## Creating a new Excel Workbook

A new workbook can be created by using a [Create](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Spreadsheet.Spreadsheet.html#Syncfusion_Windows_Forms_Spreadsheet_Spreadsheet_Create_System_Int32_) method with specified number of worksheets. By default, a workbook will be created with single worksheet.
3.Ribbon can be added to the application by dragging `SpreadsheetRibbon` to the Designer area.

{% tabs %}
{% highlight c# %}

spreadsheet.Create(2);

{% highlight c# tabtitle="Form1.Designer.cs" %}
....
public Form1()
{
....
private void InitializeComponent()
{
Spreadsheet spreadsheet = new Spreadsheet();
SpreadsheetRibbon spreadsheetRibbon = new SpreadsheetRibbon();
}
....
}
....
{% endhighlight %}
{% endtabs %}

## Opening an existing Excel Workbook

The Excel Workbook can be opened in Spreadsheet using the [Open](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Spreadsheet.Spreadsheet.html#Syncfusion_Windows_Forms_Spreadsheet_Spreadsheet_Open_Syncfusion_XlsIO_IWorkbook_) method in various ways,
4.To make an interaction between Ribbon items and `Spreadsheet`, bind the Spreadsheet as DataContext to the `SpreadsheetRibbon`.

{% tabs %}
{% highlight c# %}

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

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

//Using Workbook,
spreadsheet.Open(IWorkbook workbook);

{% endhighlight %}
{% endtabs %}

{% tabs %}
{% highlight c# %}

spreadsheet.Open (@"..\..\Data\Outline.xlsx");

{% highlight c# tabtitle="Form1.Designer.cs" %}
....
public Form1()
{
....
private void InitializeComponent()
{
Spreadsheet spreadsheet = new Spreadsheet();
SpreadsheetRibbon spreadsheetRibbon = new SpreadsheetRibbon();
spreadsheetRibbon.Spreadsheet = spreadsheet;
}
....
}
....
{% endhighlight %}
{% endtabs %}

![Opening an existing excel workbook in WindowsForms Spreadsheet](getting-started_images/windowsforms-spreadsheet-opening-an-existing-excel-workbook.png)


Opening Excel File in Spreadsheet
{:.caption}

## Saving the Excel Workbook

The Excel workbook can be saved in Spreadsheet using [Save](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Spreadsheet.Spreadsheet.html#Syncfusion_Windows_Forms_Spreadsheet_Spreadsheet_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.

{% tabs %}
{% highlight c# %}

spreadsheet.Save();
{% endtabcontent %}

{% tabcontent Via Coding %}

{% endhighlight %}
{% endtabs %}

You can also use [SaveAs](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Spreadsheet.Spreadsheet.html#Syncfusion_Windows_Forms_Spreadsheet_Spreadsheet_SaveAs) method directly to save the existing excel file with modifications.
Spreadsheet is available in the following namespace **[Syncfusion.Windows.Forms.Spreadsheet](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Spreadsheet.html)** and it can be created programmatically by using below code.

The `SaveAs` method in Spreadsheet can be used in various ways,
_For_ _Spreadsheet_

{% tabs %}
{% highlight c# %}

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

//Using String,
spreadsheet.SaveAs (string file);
{% highlight c# tabtitle="Form1.cs" %}

....
public Form1()
{
InitializeComponent();
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);
}
....

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

{% endhighlight %}
{% endtabs %}

## Displaying charts and sparklines

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

Assembly: **Syncfusion.SpreadsheetHelper.Windows.dll**
{% endtabcontents %}

### Charts

Create an instance of Syncfusion.Windows.Forms.SpreadsheetHelper.[GraphicChartCellRenderer](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.SpreadsheetHelper.GraphicChartCellRenderer.html) and add that renderer into [GraphicCellRenderers](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Spreadsheet.GraphicCells.GraphicModel.html#Syncfusion_Windows_Forms_Spreadsheet_GraphicCells_GraphicModel_GraphicCellRenderers) collection by using the helper method [AddGraphicChartCellRenderer](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Spreadsheet.GraphicCells.GraphicCellHelper.html#Syncfusion_Windows_Forms_Spreadsheet_GraphicCells_GraphicCellHelper_AddGraphicChartCellRenderer_Syncfusion_Windows_Forms_Spreadsheet_Spreadsheet_Syncfusion_Windows_Forms_Spreadsheet_GraphicCells_IGraphicCellRenderer_) which is available under the namespace `Syncfusion.Windows.Forms.Spreadsheet.GraphicCells`.
## Run the application

{% tabs %}
{% highlight c# %}
Press <kbd>Ctrl</kbd>+<kbd>F5</kbd> (Windows) or <kbd>⌘</kbd>+<kbd>F5</kbd> (macOS) to launch the application.The output will appear as follows:

public Form1()
{
InitializeComponent();

//For importing charts,
this.spreadsheet.AddGraphicChartCellRenderer(new GraphicChartCellRenderer());
}

{% endhighlight %}
{% endtabs %}

### Sparklines

Create an instance of Syncfusion.Windows.Forms.SpreadsheetHelper.[SparklineCellRenderer](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.SpreadsheetHelper.SparklineCellRenderer.html) and add that renderer into Spreadsheet by using the helper method [AddSparklineCellRenderer](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Spreadsheet.GraphicCells.GraphicCellHelper.html#Syncfusion_Windows_Forms_Spreadsheet_GraphicCells_GraphicCellHelper_AddSparklineCellRenderer_Syncfusion_Windows_Forms_Spreadsheet_Spreadsheet_Syncfusion_Windows_Forms_Spreadsheet_CellRenderer_ISpreadsheetCellRenderer_) which is available under the namespace `Syncfusion.Windows.Forms.Spreadsheet.GraphicCells`.

{% tabs %}
{% highlight c# %}
![Adding control via coding in WindowsForms Spreadsheet](getting-started_images/windowsforms-spreadsheet-coding.png)

public Form1()
{
InitializeComponent();

//For importing sparklines,
this.spreadsheet.AddSparklineCellRenderer(new SparklineCellRenderer());
}
To learn how to create, open, and save files in the WPF Spreadsheet Component, see [Workbook Operations](Workbook-Operations).

{% endhighlight %}
{% endtabs %}
N>[View Sample in GitHub.](https://github.com/SyncfusionExamples/winforms-spreadsheet-getting-started)

N> You can refer to our [WinForms Spreadsheet](https://www.syncfusion.com/winforms-ui-controls/spreadsheet) control feature tour page for its groundbreaking feature representations. You can also explore our [WinForms Spreadsheet example](https://github.com/syncfusion/winforms-demos/tree/master/spreadsheet) that shows you how to render and configure the Spreadsheet.
## See Also
- [Data Management](Data-Management)
- [Display Charts and Sparklines](Shapes)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading