Syncfusion AI Assistant

How can I help you?

Getting Started with the Blazor Spreadsheet in Web App

27 May 20267 minutes to read

This section briefly explains how to include the Syncfusion® Blazor Spreadsheet component in a Blazor Web App using Visual Studio, Visual Studio Code, and the .NET CLI.

Prerequisites

Create a New Blazor Web App in Visual Studio

Create a Blazor Web App using Visual Studio 2022 via Microsoft Templates or the Syncfusion® Blazor Extension.

NOTE

Configure the appropriate Interactive render mode and Interactivity location while creating a Blazor Web App. For detailed information, refer to the interactive render mode documentation.

Install Syncfusion® Blazor Spreadsheet NuGet Packages

If you utilize WebAssembly or Auto render modes in the Blazor Web App need to be install Syncfusion® Blazor components NuGet packages within the client project.

To add Syncfusion Blazor Spreadsheet component in the app, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search and install:

Alternatively, you can utilize the following package manager command to achieve the same.

Install-Package Syncfusion.Blazor.Spreadsheet -Version 33.2.3
Install-Package Syncfusion.Blazor.Themes -Version 33.2.3

Prerequisites

Create a New Blazor Web App in Visual Studio Code

Create a Blazor Web App using Visual Studio Code via Microsoft Templates or the Syncfusion® Blazor Extension.

NOTE

Configure the appropriate Interactive render mode and Interactivity location while creating a Blazor Web App. For detailed information, refer to the interactive render mode documentation.

For example, in a Blazor Web App with the Auto interactive render mode, use the following commands.

dotnet new blazor -o BlazorWebApp -int Auto
cd BlazorWebApp
cd BlazorWebApp.Client

NOTE

For more information on creating a Blazor Web App with various interactive modes and locations, see Render interactive modes.

Install Syncfusion® Blazor Spreadsheet NuGet Packages

If you utilize WebAssembly or Auto render modes in the Blazor Web App need to be install Syncfusion® Blazor components NuGet packages within the client project.

  • Press Ctrl+` to open the integrated terminal in Visual Studio Code.
  • Ensure you’re in the project root directory where your .csproj file is located.
  • Run the following command to install a Syncfusion.Blazor.Spreadsheet and Syncfusion.Blazor.Themes NuGet package and ensure all dependencies are installed.
dotnet add package Syncfusion.Blazor.Spreadsheet -v 33.2.3
dotnet add package Syncfusion.Blazor.Themes -v 33.2.3
dotnet restore

Prerequisites

Install the latest version of .NET SDK. If you previously installed the SDK, you can determine the installed version by executing the following command in a command prompt (Windows) or terminal (macOS) or command shell (Linux).

dotnet --version

Create a Blazor Web App using .NET CLI

Run the following command to create a new Blazor Web App in a command prompt (Windows) or terminal (macOS) or command shell (Linux). For detailed instructions, refer to the Blazor Web App Getting Started documentation.

For example, in a Blazor Web App with the Auto interactive render mode, use the following commands:

dotnet new blazor -o BlazorWebApp -int Auto
cd BlazorWebApp
cd BlazorWebApp.Client

Install Syncfusion® Blazor Spreadsheet and Themes NuGet in the App

If you utilize WebAssembly or Auto render modes in the Blazor Web App need to be install Syncfusion® Blazor components NuGet packages within the client project.

  • Open a command prompt, terminal, or shell.
  • Ensure you’re in the project root directory where your .csproj file is located (or the Client project if applicable).
  • Run the following command to install a Syncfusion.Blazor.Spreadsheet and Syncfusion.Blazor.Themes NuGet package and ensure all dependencies are installed.
dotnet add package Syncfusion.Blazor.Spreadsheet -v 33.2.3
dotnet add package Syncfusion.Blazor.Themes -v 33.2.3
dotnet restore

Add import namespaces

After the packages are installed, open the ~/_Imports.razor file in the client project and import the Syncfusion.Blazor and Syncfusion.Blazor.Spreadsheet namespaces.

@using Syncfusion.Blazor
@using Syncfusion.Blazor.Spreadsheet

Register Syncfusion® Blazor Service

Register the Syncfusion Blazor service in the Program.cs file of your Blazor Web App.

....
using Syncfusion.Blazor;
....

builder.Services.AddSyncfusionBlazor();

....

NOTE

If the Interactive Render Mode is set to WebAssembly or Auto, register the Syncfusion® Blazor service in Program.cs files of both the server and client projects in your Blazor Web App.

Add stylesheet and script resources

The theme stylesheet and script can be accessed from NuGet through Static Web Assets. Include the stylesheet reference in the <head> section and the script reference at the end of the <body> in the ~/Components/App.razor file as shown below.

<head>
    ....
    <link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
</head>
<body>
    ....
    <script src="_content/Syncfusion.Blazor.Spreadsheet/scripts/syncfusion-blazor-spreadsheet.min.js" type="text/javascript"></script>
</body>

NOTE

Check out the Blazor Themes topic to explore supported ways (such as static assets, CDN, and CRG) to apply themes in your Blazor application. Also, check out the Adding Script Reference topic to learn different approaches for adding script references in your Blazor application.

Add Syncfusion® Blazor Spreadsheet component

Add the Syncfusion Blazor Spreadsheet component in the ~/Components/Pages/*.razor file. If the interactivity location is set to Per page/component in the Web App, define a render mode at the top of the ~/Pages/*.razor file. (For example, InteractiveServer, InteractiveWebAssembly or InteractiveAuto).

NOTE

If the Interactivity Location is set to Global with Auto or WebAssembly, the render mode is automatically configured in the App.razor file by default.

@* desired render mode define here *@
@rendermode InteractiveServer
@page "/"
@using Syncfusion.Blazor.Spreadsheet

<SfSpreadsheet>
    <SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>

Press Ctrl+F5 (Windows) or +F5 (macOS) to launch the application. This will render the Syncfusion Blazor Spreadsheet in your default web browser. The output will appear as follows:

Blazor Spreadsheet

You can also experiment directly using the interactive playground below for a quick demo:

To learn how to open workbooks, bind data, or save files in the Spreadsheet component, see Open and Save.

NOTE

View Sample In GitHub..

See Also