Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 106 additions & 27 deletions Document-Processing/Excel/Spreadsheet/Blazor/cell-range.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
---
layout: post
title: Managing Cell Ranges in the Blazor Spreadsheet Component | Syncfusion
description: Check out and learn to manage cell range features such as formatting, autofill, and clear options in the Syncfusion Blazor Spreadsheet component and more.
description: Learn how to manage cell range features such as formatting, autofill, and clear options in the Syncfusion Blazor Spreadsheet component and more.
platform: document-processing
control: Spreadsheet
documentation: ug
---

# Managing Cell Ranges in Blazor Spreadsheet component
# Managing Cell Ranges in the Blazor Spreadsheet Component

A cell range is a set of selected cells in a Spreadsheet, typically specified using A1 notation (for example, `A1:B10`). A range may be a single cell or a contiguous block of cells that can be manipulated or processed collectively.

## Cell formatting

To know more about cell formatting, refer [here](./formatting#text-and-cell-formatting).
The Spreadsheet component supports a wide range of cell-formatting operations—including text styling (font family, size, color, and weight), cell fill, borders, alignment, number formats, and conditional formatting—that can be applied to a single cell, a selected range, or the entire worksheet. For more details, refer to the [Text and Cell Formatting](./formatting#text-and-cell-formatting) documentation.

## Autofill

Autofill is used to fill cells with data that follows a pattern or is based on data in other cells. It helps avoid entering repetitive data manually. The [AllowAutofill](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_AllowAutofill) property can be used to enable or disable this feature.
The Autofill feature automatically populates adjacent cells with data that follows a pattern or extends values from the source cells. It helps avoid entering repetitive data manually. The [AllowAutofill](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_AllowAutofill) property can be used to enable or disable this feature.

* The default value of the [AllowAutofill](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_AllowAutofill) property is **true**.

To enable or disable autofill declaratively, set the `AllowAutofill` property on the `SfSpreadsheet` component. For example:

{% tabs %}
{% highlight razor tabtitle="Index.razor" %}

@using Syncfusion.Blazor.Spreadsheet

<SfSpreadsheet AllowAutofill="true">
<SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>

{% endhighlight %}
{% endtabs %}

Autofill can be performed in one of the following ways:

* Drag and drop the cell using the fill handle element.
* Select the source cell or range, then drag and drop the selection using the fill handle element to extend the values to adjacent cells.
* Use the [AutofillAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_AutofillAsync_System_String_System_String_) method programmatically.

### Autofill options

Autofill supports multiple behaviors that control how adjacent cells are populated when using the fill handle. The available options are:
Autofill supports multiple behaviors that control how adjacent cells are populated when using the fill handle. After dragging the fill handle, the **AutoFillOptions** menu appears as a popup near the destination range. You can also right-click the destination range and select **AutoFillOptions** to access the same options. The available options are:

- Copy Cells
- Fill Series
Expand All @@ -48,13 +63,13 @@ Applies only the source styling—number format, font, fill color, borders, and

#### Fill Without Formatting

Continues the detected series into the destination range but retains the destinations existing formatting. After dragging the fill handle, choose **Fill Without Formatting** from the **AutoFillOptions** menu to apply only the new values while keeping the target style intact.
Continues the detected series into the destination range but retains the destination's existing formatting. After dragging the fill handle, choose **Fill Without Formatting** from the **AutoFillOptions** menu to apply only the new values while keeping the target style intact.

The following illustration demonstrates the use of autofill in the Spreadsheet component.

![Autofill Illustration](images/autofill.gif)

The [AutofillAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_AutofillAsync_System_String_System_String_) method accepts string parameters in A1 notation for `fillRange` and `dataRange`. The available parameters are:
The [AutofillAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_AutofillAsync_System_String_System_String_) method accepts string parameters in A1 notation for `fillRange` and `dataRange`. The following table lists the available parameters:

| Parameter | Type | Description |
| -- | -- | -- |
Expand All @@ -67,16 +82,17 @@ The [AutofillAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Sp
{% tabs %}
{% highlight razor tabtitle="Index.razor" %}

@page "/"
@using Syncfusion.Blazor.Spreadsheet

<button @onclick="AutofillRangeHandler">Autofill</button>
<SfSpreadsheet @ref="spreadsheetObj" DataSource="DataSourceBytes">
<SfSpreadsheet @ref="SpreadsheetInstance" DataSource="DataSourceBytes">
<SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>

@code {
public byte[] DataSourceBytes { get; set; }
public SfSpreadsheet spreadsheetObj;
public SfSpreadsheet SpreadsheetInstance;

protected override void OnInitialized()
{
Expand All @@ -87,14 +103,14 @@ The [AutofillAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Sp
public async Task AutofillRangeHandler()
{
// Basic usage with only the fill range parameter.
await spreadsheetObj.AutofillAsync("B7:B8");
await SpreadsheetInstance.AutofillAsync("B7:B8");
}
}

{% endhighlight %}
{% endtabs %}

## Events
## Autofill Events

The Blazor Spreadsheet provides events that are triggered during autofill operations, such as [AutofillActionBegin](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.AutofillActionBeginEventArgs.html) and [AutofillActionEnd](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.AutofillActionEndEventArgs.html). These events enable the execution of custom actions before and after an autofill operation, allowing for validation, customization, and response handling.

Expand All @@ -110,16 +126,17 @@ This event is useful for scenarios where autofill behavior needs to be controlle

The event uses the [AutofillActionBeginEventArgs](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.AutofillActionBeginEventArgs.html) class, which includes the following properties:

| Event Arguments | Description |
|----------------|-------------|
| FillRange (read-only) | The address of the target range for the autofill operation (e.g., "Sheet1!A2:A5"). |
| DataRange (read-only) | The source data range for the autofill operation (e.g., "Sheet1!A1:A1"). |
| Direction (read-only) | The direction of the autofill operation ("Down", "Right", "Up", or "Left"). |
| Cancel | A boolean value to cancel the autofill operation. |
| Event Arguments | Type | Description |
|---|---|---|
| FillRange (read-only) | string | The address of the target range for the autofill operation (e.g., "Sheet1!A2:A5"). |
| DataRange (read-only) | string | The source data range for the autofill operation (e.g., "Sheet1!A1:A1"). |
| Direction (read-only) | string | The direction of the autofill operation ("Down", "Right", "Up", or "Left"). |
| Cancel | bool | A boolean value to cancel the autofill operation. |

{% tabs %}
{% highlight razor tabtitle="Index.razor" %}

@page "/"
@using Syncfusion.Blazor.Spreadsheet

<SfSpreadsheet DataSource="DataSourceBytes" AutofillActionBegin="OnAutofillActionBegin">
Expand Down Expand Up @@ -160,21 +177,22 @@ The [AutofillActionEnd](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.

**Purpose**

This event is useful for scenarios where `post-autofill` actions are needed, such as logging the autofill operation, updating related data, or triggering additional UI updates.
This event is useful for scenarios where actions after the autofill are needed, such as logging the autofill operation, updating related data, or triggering additional UI updates.

**Event Arguments**

The event uses the [AutofillActionEndEventArgs](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.AutofillActionEndEventArgs.html) class, which includes the following properties:

| Event Arguments | Description |
|----------------|-------------|
| FillRange (read-only) | The address of the target range where the autofill was applied (e.g., "Sheet1!A2:A5"). |
| DataRange (read-only) | The source data range used for the autofill operation (e.g., "Sheet1!A1:A1"). |
| Direction (read-only) | The direction of the autofill operation ("Down", "Right", "Up", or "Left"). |
| Event Arguments | Type | Description |
|---|---|---|
| FillRange (read-only) | string | The address of the target range where the autofill was applied (e.g., "Sheet1!A2:A5"). |
| DataRange (read-only) | string | The source data range used for the autofill operation (e.g., "Sheet1!A1:A1"). |
| Direction (read-only) | string | The direction of the autofill operation ("Down", "Right", "Up", or "Left"). |

{% tabs %}
{% highlight razor tabtitle="Index.razor" %}

@page "/"
@using Syncfusion.Blazor.Spreadsheet

<SfSpreadsheet DataSource="DataSourceBytes" AutofillActionEnd="OnAutofillActionEnd">
Expand Down Expand Up @@ -202,13 +220,17 @@ The event uses the [AutofillActionEndEventArgs](https://help.syncfusion.com/cr/b

## Clear

The clear functionality helps remove cell contents (formulas and data), formats (including number formats), and hyperlinks from a selected range.
The Clear functionality removes cell contents (formulas and data), formats (including number formats), and hyperlinks from a selected range.

### Applying the clear functionality

The clear support can be applied using the following way:
Clearing can be performed through the user interface (UI) using any of the following methods:

You can apply the clear functionality by selecting the **Clear** icon in the **Ribbon** under the **Home** tab.
**Using the Ribbon**

- Select a cell or a range of cells to clear.
- In the **Home** tab of the **Ribbon**, click the **Clear** drop-down arrow.
- Select one of the following options from the drop-down menu:

| Option | Use |
| -- | -- |
Expand All @@ -220,3 +242,60 @@ You can apply the clear functionality by selecting the **Clear** icon in the **R
The following image displays the clear options available in the Ribbon toolbar under the **Home** tab of the Blazor Spreadsheet.

![Clear options in the Blazor Spreadsheet](images/clear-feature.png)

**Using the Context Menu**

- Select a cell or a range of cells to clear.
- Right-click the selected range to open the context menu.
- Select **Clear Contents** to remove only the formulas and data from the current selection.

### Clear programmatically

The [ClearAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_ClearAsync_Syncfusion_Blazor_Spreadsheet_ClearOperationType_System_String_) method clears contents, formatting, hyperlinks, or all aspects of the specified range or current selection in the spreadsheet.

The available parameters are:

| Parameter | Type | Description |
| -- | -- | -- |
| options | Enum | Specifies the type of clear operation to perform. The available values are: `ClearContents`, `ClearFormats`, `ClearHyperlinks`, and `ClearAll`|
| range | string | The A1-style range to clear |

**Remarks**

* The method parses the provided `range` and resolves the target worksheet and range before performing the clear operation.
* If `range` is `null` or empty, the operation is applied to the current selection.

{% tabs %}
{% highlight razor tabtitle="Index.razor" %}

@page "/"
@using Syncfusion.Blazor.Spreadsheet

<SfButton OnClick="ClearHandler" Content="Clear Cells"></SfButton>

<SfSpreadsheet @ref="SpreadsheetInstance" DataSource="DataSourceBytes">
<SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>

@code {
public byte[] DataSourceBytes { get; set; }
public SfSpreadsheet SpreadsheetInstance { get; set; }

protected override void OnInitialized()
{
string filePath = "wwwroot/Sample.xlsx";
DataSourceBytes = File.ReadAllBytes(filePath);
}

public async Task ClearHandler()
{
// Clears only contents from range A1:A10 on Sheet1.
await SpreadsheetInstance.ClearAsync(ClearOperationType.ClearContents, "Sample!A1:A10");

// Clears only formats from the current selection.
await SpreadsheetInstance.ClearAsync(ClearOperationType.ClearFormats);
}
}

{% endhighlight %}
{% endtabs %}
Loading