How can I help you?
Rows and columns in Blazor Spreadsheet component
29 Oct 20254 minutes to read
Spreadsheet is a tabular format consisting of rows and columns. The intersection point of rows and columns are called as cells. The list of operations that you can perform in rows and columns are,
- Insert
- Setting Column and Row Count
Insert
You can insert rows or columns anywhere in a spreadsheet.
Row
The rows can be inserted in the following ways,
- Using
InsertRowAsyncmethod, you can insert the rows once the component is loaded. - Using context menu, insert the rows in the desired position.
The following code example shows the options for inserting rows in the spreadsheet.
@using Syncfusion.Blazor.Spreadsheet
@using Syncfusion.Blazor.Buttons
<SfButton OnClick="InsertRowsHandler" Content="Insert Rows"></SfButton>
<SfSpreadsheet @ref="@SpreadsheetInstance" DataSource="DataSourceBytes">
<SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>
@code {
public byte[] DataSourceBytes { get; set; }
public SfSpreadsheet SpreadsheetInstance;
protected override void OnInitialized()
{
string filePath = "wwwroot/Sample.xlsx";
DataSourceBytes = File.ReadAllBytes(filePath);
}
public async Task InsertRowsHandler()
{
// Insert 2 rows above row index 0 in the active sheet
await SpreadsheetInstance.InsertRowAsync(0, 2);
// Insert 3 rows below row index 2 in the sheet named "Sheet2"
await SpreadsheetInstance.InsertRowAsync(2, 3, "Sheet2", RowPosition.Below);
// Insert 1 row above row index 1 in the active sheet
await SpreadsheetInstance.InsertRowAsync(1, 1, null, RowPosition.Above);
// Insert 4 rows below row index 3 in the sheet at index 3
await SpreadsheetInstance.InsertRowAsync(3, 4, 3, RowPosition.Below);
}
}Column
The columns can be inserted in the following ways,
- Using
InsertColumnAsyncmethod, you can insert the columns once the component is loaded. - Using context menu, insert the columns in the desired position.
The following code example shows the options for inserting columns in the spreadsheet.
@using Syncfusion.Blazor.Spreadsheet
@using Syncfusion.Blazor.Buttons
<SfButton OnClick="InsertColumnsHandler" Content="Insert Columns"></SfButton>
<SfSpreadsheet @ref="@SpreadsheetInstance" DataSource="DataSourceBytes">
<SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>
@code {
public byte[] DataSourceBytes { get; set; }
public SfSpreadsheet SpreadsheetInstance;
protected override void OnInitialized()
{
string filePath = "wwwroot/Sample.xlsx";
DataSourceBytes = File.ReadAllBytes(filePath);
}
public async Task InsertColumnsHandler()
{
// Insert 2 columns to the right of column index 2
await SpreadsheetInstance.InsertColumnAsync(2, 2);
// Insert 3 columns to the left of column index 5
await SpreadsheetInstance.InsertColumnAsync(5, 3, null, ColumnPosition.Left);
// Insert 1 column to the right of column B in Sheet2
await SpreadsheetInstance.InsertColumnAsync(1, 1, "Sheet2", ColumnPosition.Right);
// Insert 4 columns to the left of column D in the sheet at index 3
await SpreadsheetInstance.InsertColumnAsync(3, 4, 3, ColumnPosition.Left);
}
}Setting Row and Column Count
The Blazor Spreadsheet component enables you to define the initial number of rows and columns using the RowCount and ColumnCount properties.
- The default
RowCountis 1000. - The default
ColumnCountis 200.
Rendering Behavior
-
Without Data Source:
- When no data is bound to the spreadsheet, the sheet renders empty cells up to the specified row and column counts.
-
With Data Source (e.g., byte array or imported file):
- If the data source contains fewer rows and columns than the specified row and column counts, the spreadsheet renders additional empty rows and columns to meet those counts.
- If the data source contains more rows and columns than the specified row and column counts, the spreadsheet renders enough rows and columns to display all the data (i.e., it extends beyond those counts to fit the data). Your data is never truncated by these properties.
You can set these properties as follows:
@using Syncfusion.Blazor.Spreadsheet
<SfSpreadsheet DataSource="DataSourceBytes" RowCount="1200" ColumnCount="300" >
<SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>
@code {
public byte[] DataSourceBytes { get; set; }
protected override void OnInitialized()
{
string filePath = "wwwroot/Sample.xlsx";
DataSourceBytes = File.ReadAllBytes(filePath);
}
}