Getting Started with WPF SpreadsheetControl (Classic)
4 May 20213 minutes to read
Creating a WPF Application
The following are steps to create a new WPF application in Visual Studio:
-
Open Visual Studio.
-
Click File tab and navigate to New > Project.
-
In the New Project dialog box, select WPF Application, enter a name for the application in the Name field and click OK.
-
Now, a new WPF application will be created.
Adding Spreadsheet Control to WPF Application
Through Visual Studio
Following are the steps to add the Spreadsheet control to WPF application using Visual Studio.
-
Create a new WPF application in Visual Studio.
-
In Visual Studio Toolbox, click Syncfusion WPF Toolbox tab.
-
Drag SpreadsheetControl to the Designer area.
-
Customize the properties of SpreadsheetControl using Properties window.
NOTE
To add the SpreadsheetRibbon control to your application, drag SpreadsheetRibbon to the Designer area and set the Spreadsheet control as a DataContext as shown the following code.
<syncfusion:SpreadsheetRibbon DataContext="{Binding ElementName=spreadsheetControl1}"/>
Through XAML and C#
You can also add the Spreadsheet control to a WPF application through XAML and C#. The following code example illustrates this.
<syncfusion:SpreadsheetControl HorizontalAlignment="Left" Name="spreadsheetControl1" VerticalAlignment="Top" />
SpreadsheetControl Spreadsheet1 = new SpreadsheetControl();LayoutRoot.Children.Add(Spreadsheet1);
Dim Spreadsheet1 As SpreadsheetControl = New SpreadsheetControl()LayoutRoot.Children.Add(Spreadsheet1)
Loading Excel Files in Spreadsheet Control
You can open the Excel document in the Spreadsheet control using ImportFromExcel method. The following code illustrates this.
FileStream stream = new FileStream(@"..\..\Data\DefaultSheet.xlsx", FileMode.Open);
spreadsheet.ImportFromExcel(stream);
Dim stream As FileStream = New FileStream("..\..\Data\DefaultSheet.xlsx", FileMode.Open)spreadsheet.ImportFromExcel(stream)
NOTE
You can also open the Excel document using ImportFromExcelCommand. When you execute the ImportFromExcelCommand it will display the Open dialog box. Using this Open dialog, you can open the Excel document in the Spreadsheet control.
Appearance and Structure of the Controls
Structure of the SpreadsheetRibbon Control
Structure of the Spreadsheet Control
Architecture
The Spreadsheet control supports ControlTemplate to define its content. By default, its content includes a TabControlExt object that contains number of TabItemExt based on sheet count. The TabItemExt contains a ScrollViewer object that contains a SpreadsheetGrid object.
The following sketch illustrates the Spreadsheet control architecture.
Accessing the Underlying Grid control
The Spreadsheet control is a control derived class that has its own properties. You can use Grid control derived property namely ActiveSpreadsheetGrid to get its grid-like behavior. To access the underlying Grid control associated with the Spreadsheet control, you can use the SpreadsheetControl.GridProperties.ActiveSpreadsheetGrid property.