BlazorDatasheet 0.9.3
dotnet add package BlazorDatasheet --version 0.9.3
NuGet\Install-Package BlazorDatasheet -Version 0.9.3
<PackageReference Include="BlazorDatasheet" Version="0.9.3" />
<PackageVersion Include="BlazorDatasheet" Version="0.9.3" />
<PackageReference Include="BlazorDatasheet" />
paket add BlazorDatasheet --version 0.9.3
#r "nuget: BlazorDatasheet, 0.9.3"
#addin nuget:?package=BlazorDatasheet&version=0.9.3
#tool nuget:?package=BlazorDatasheet&version=0.9.3
BlazorDatasheet
A simple datasheet component for editing tabular data.
<img width="512" alt="DatasheetScreenshot" src="https://github.com/user-attachments/assets/b58fa2f3-f49d-4b20-9cbb-3ae1039d88bc">
Features
- Data editing
- Built in editors including text, date, select, boolean, text area, enum
- Add custom editors for any data type
- Conditional formatting
- Data validation
- Formula
- Keyboard navigation
- Copy and paste from tabulated data
- Virtualization - handles many cells at once in both rows & cols.
Demo: https://anmcgrath.github.io/BlazorDatasheet/
Getting Started
Install the NuGet package
dotnet add package BlazorDatasheet
Configure Program.cs
In Program.cs, add the required services:
builder.Services.AddBlazorDatasheet();
Import JS/CSS
In _Layout.cshtml or index.html add
<link href="_content/BlazorDatasheet/sheet-styles.css" rel="stylesheet"/>
and
<script src="_content/BlazorDatasheet/blazor-datasheet.js" type="text/javascript"></script>
Blazor Datasheet provides a Datasheet Blazor component that accepts a Sheet.
A Sheet holds the data and configuration for a Datasheet. The data is set per Cell, or can be built using the ObjectEditorBuilder, which creates a datasheet based on a list of objects.
The following code displays an empty 3 x 3 data grid.
<Datasheet
Sheet="sheet"/>
@code{
private Sheet sheet;
protected override void OnInitialized()
{
sheet = new Sheet(3, 3);
}
}
The default editor is the text editor, but can be changed by defining the Type property of each cell.
Setting & getting cell values
Cell values can be set in a few ways:
sheet.Cells[0, 0].Value = "Test"
sheet.Range("A1").Value = "Test";
sheet.Cells.SetValue(0, 0, "Test");
sheet.Commands.ExecuteCommand(new SetCellValueCommand(0, 0, "Test"));
Cell values are stored internally inside a CellValue
wrapper. Values are converted implicitly when set above and a CellValueType
is assigned to the cell.
The CellValueType
is used for formula evaluation and can be one of the following:
Empty = 0,
Error = 1,
Array = 2,
Unknown = 3,
Sequence = 4,
Reference = 5,
Number = 6,
Date = 7,
Text = 8,
Logical = 9,
This conversion can be controlled, for example when setting the cell type to "text", values will always be stored as strings and no conversion will be made.
The conversion can additionally be modified by using the Sheet.Cells.BeforeCellValueConversion
event. By changing the NewValue
property of the argument, the value that is stored is modified.
Formula
Formula can be applied to cells. When the cells or ranges that the formula cells reference change, the cell value is re-calculated.
sheet.Cells[0, 0].Formula = "=10+A2"
Formatting
Cell formats can be set in the following ways:
sheet.Range("A1:A2").Format = new CellFormat() { BackgroundColor = "red" };
sheet.Commands.ExecuteCommand(
new SetFormatCommand(new RowRegion(10, 12), new CellFormat() { ForegroundColor = "blue" }));
sheet.SetFormat(sheet.Range(new ColumnRegion(5)), new CellFormat() { FontWeight = "bold" });
sheet.Cells[0, 0].Format = new CellFormat() { TextAlign = "center" };
When a cell format is set, it will be merged into any existing cell formats in the region that it is applied to. Any non-null format paremeters will be merged:
sheet.Range("A1").Format = new CellFormat() { BackgroundColor = "red" };
sheet.Range("A1:A2").Format = new CellFormat() { ForegroundColor = "blue" };
var format = sheet.Cells[0, 0].Format; // backroundColor = "red", foreground = "blue"
var format2 = sheet.Cells[1, 0].Format; // foreground = "blue"
Cell types
The cell type specifies which renderer and editor are used for the cell. Cell types also help with explicit conversions when cell values are set.
sheet.Range("A1:B5").Type = "boolean"; // renders a checkbox
Custom editors and renderers can be defined. See the examples for more information.
Validation
Data validation can be set on cells/ranges. There are two modes of validation: strict and non-strict. When a validator is strict, the cell value will not be set by the editor if it fails validation.
If validation is not strict, the value can be set during editing but will show a validation error when rendered.
Although a strict validation may be set on a cell, the value can be changed programmatically, but it will display as a validation error.
sheet.Validators.Add(new ColumnRegion(0), new NumberValidator(isStrict: true));
Regions and ranges
A region is a geometric construct, for example:
var region = new Region(0, 5, 0, 5); // r0 to r5, c0 to c5
var cellRegion = new Region(0, 0); // cell A1
var colRegion = new ColumnRegion(0, 4); // col region spanning A to D
var rowRegion = new RowRegion(0, 3); // row region spanning 1 to 4
A range is a of region that also knows about the sheet. Ranges can be used to set certain parts of the sheet.
var range = sheet.Range("A1:C5");
var range = sheet.Range(new ColumnRegion(0));
var range = sheet.Range(0, 0, 4, 5);
Support
Community Links
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- BlazorDatasheet.Core (>= 0.9.3)
- BlazorDatasheet.DataStructures (>= 0.9.3)
- BlazorDatasheet.Formula.Core (>= 0.9.3)
- Microsoft.AspNetCore.Components.Web (>= 8.0.16)
-
net9.0
- BlazorDatasheet.Core (>= 0.9.3)
- BlazorDatasheet.DataStructures (>= 0.9.3)
- BlazorDatasheet.Formula.Core (>= 0.9.3)
- Microsoft.AspNetCore.Components.Web (>= 9.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
0.9.3 | 916 | 5/18/2025 |
0.9.2 | 108 | 5/17/2025 |
0.9.1 | 820 | 5/1/2025 |
0.9.0 | 374 | 4/21/2025 |
0.8.2 | 251 | 4/15/2025 |
0.8.1 | 133 | 4/12/2025 |
0.8.0 | 517 | 4/8/2025 |
0.7.2 | 480 | 4/1/2025 |
0.7.1 | 245 | 3/22/2025 |
0.7.1-alpha | 146 | 3/20/2025 |
0.7.0 | 297 | 3/16/2025 |
0.6.0 | 754 | 3/3/2025 |
0.5.3 | 557 | 2/16/2025 |
0.5.2.7 | 1,028 | 1/10/2025 |
0.5.2.6 | 109 | 1/10/2025 |
0.5.2.5 | 897 | 12/20/2024 |
0.5.2.4 | 604 | 12/11/2024 |
0.5.2.3 | 173 | 12/7/2024 |
0.5.2.2 | 199 | 12/4/2024 |
0.5.2.2-alpha | 126 | 11/27/2024 |
0.5.2.1 | 385 | 11/27/2024 |
0.5.2 | 111 | 11/27/2024 |
0.5.1 | 116 | 11/26/2024 |
0.5.0 | 139 | 11/24/2024 |
0.4.0 | 1,146 | 10/23/2024 |
0.3.0.1 | 2,625 | 7/6/2024 |
0.3.0 | 286 | 6/30/2024 |
0.2.1 | 882 | 5/19/2024 |