This quick start guide will help you create a simple WPF application, install NuGet packages, and add Spread WPF controls to your Visual Studio project. You can get started with Spread for WPF with NuGet packages in .NET Framework and .NET Core editions by following the steps mentioned in the section below.
To create a simple WPF application (.NET Framework) in Visual Studio, complete the following steps:
Copy Code
|
|
---|---|
GrapeCity.Wpf.SpreadSheet.GcSpreadSheet, GrapeCity.Wpf.SpreadSheet |
XAML |
Copy Code
|
---|---|
xmlns:gss="http://schemas.grapecity.com/windows/spreadsheet/2020" |
Create Window_Loaded event and assign names to the GcSpreadSheet and GcFormulaBar controls in the XAML code.
The XAML markup should look like the following:
XAML |
Copy Code
|
---|---|
<Window x:Class="YourApplicationName.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:gss="http://schemas.grapecity.com/windows/spreadsheet/2020" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition/> <RowDefinition Height="350"/> <RowDefinition/> </Grid.RowDefinitions> <gss:GcFormulaBar x:Name="formulaBar1" Grid.Row="0" ShowEditingButtons="True" Expandable="True" AssociatedSpread="{x:Reference Name=spreadSheet1}"/> <gss:GcSpreadSheet x:Name="spreadSheet1" Grid.Row="1" Margin="0,0,0,149" Grid.RowSpan="2" /> </Grid> </Window> |
C# |
Copy Code
|
---|---|
private void Window_Loaded(object sender, RoutedEventArgs e) { // Create an instance of GcSpreadSheet workbook. GrapeCity.Spreadsheet.IWorkbook workbook = spreadSheet1.Workbook; // Get the default worksheet. GrapeCity.Spreadsheet.IWorksheet worksheet = spreadSheet1.Workbook.ActiveSheet; // Add data to the cells. worksheet.Cells[0, 0].Value = "Welcome to Spread for WPF"; // Save the workbook. workbook.SaveAs("SavedWorkbook.xlsx", GrapeCity.Spreadsheet.IO.FileFormat.OpenXMLWorkbook); } |
Visual Basic |
Copy Code
|
---|---|
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) ' Create an instance of GcSpreadSheet workbook. Dim workbook As GrapeCity.Spreadsheet.IWorkbook = spreadSheet1.Workbook ' Get the default worksheet. Dim worksheet As GrapeCity.Spreadsheet.IWorksheet = spreadSheet1.Workbook.ActiveSheet ' Add data to the cells. worksheet.Cells[0, 0].Value = "Welcome to Spread for WPF" ' Save the workbook. workbook.SaveAs("SavedWorkbook.xlsx", GrapeCity.Spreadsheet.IO.FileFormat.OpenXMLWorkbook) End Sub |
To create a simple WPF application (.NET Core) in Visual Studio, complete the following steps:
XAML |
Copy Code
|
---|---|
xmlns:gss="http://schemas.grapecity.com/windows/spreadsheet/2020" |
Create Window_Loaded event and assign names to the GcSpreadSheet and GcFormulaBar controls in the XAML code.
The XAML markup should look like the following:
XAML |
Copy Code
|
---|---|
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:gss="http://schemas.grapecity.com/windows/spreadsheet/2020" x:Class="YourApplicationName.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded" > <Grid> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition/> <RowDefinition Height="350"/> <RowDefinition/> </Grid.RowDefinitions> <gss:GcFormulaBar x:Name="formulaBar1" Grid.Row="0" ShowEditingButtons="True" Expandable="True" AssociatedSpread="{x:Reference Name=spreadSheet1}"/> <gss:GcSpreadSheet x:Name="spreadSheet1" Grid.Row="1" Margin="0,0,0,149" Grid.RowSpan="2" /> </Grid> </Window> |
C# |
Copy Code
|
---|---|
private void Window_Loaded(object sender, RoutedEventArgs e) { // Create an instance of GcSpreadSheet workbook. GrapeCity.Spreadsheet.IWorkbook workbook = spreadSheet1.Workbook; // Get the default worksheet. GrapeCity.Spreadsheet.IWorksheet worksheet = spreadSheet1.Workbook.ActiveSheet; // Add data to the cells. worksheet.Cells[0, 0].Value = "Welcome to Spread for WPF"; // Save the workbook. workbook.SaveAs("SavedWorkbook.xlsx", GrapeCity.Spreadsheet.IO.FileFormat.OpenXMLWorkbook); } |
Visual Basic |
Copy Code
|
---|---|
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) ' Create an instance of GcSpreadSheet workbook. Dim workbook As GrapeCity.Spreadsheet.IWorkbook = spreadSheet1.Workbook ' Get the default worksheet. Dim worksheet As GrapeCity.Spreadsheet.IWorksheet = spreadSheet1.Workbook.ActiveSheet ' Add data to the cells. worksheet.Cells[0, 0].Value = "Welcome to Spread for WPF" ' Save the workbook. workbook.SaveAs("SavedWorkbook.xlsx", GrapeCity.Spreadsheet.IO.FileFormat.OpenXMLWorkbook) End Sub |
The output will look like as below.