Skip to content

Commit 11864f8

Browse files
959853: Resolving review comments
1 parent d0ea759 commit 11864f8

1 file changed

Lines changed: 63 additions & 9 deletions

File tree

Document-Processing/Excel/Spreadsheet/Blazor/worksheet.md

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,19 @@ This method inserts one or more sheets at a specified position in the workbook w
7272
{% endtabs %}
7373

7474

75-
### Get active worksheet
75+
### Get Active Worksheet Programmatically
7676

77-
Retrieves key properties of the [GetActiveWorksheet](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_GetActiveWorksheet), including name, index, row and column counts, the active cell, and the current selection. Returns null when no active worksheet is available.
77+
Use the [GetActiveWorksheet](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_GetActiveWorksheet) method to retrieve the currently active worksheet in the Spreadsheet component. This is particularly useful to perform operations relative to the current sheet selection. The method returns key properties of the active worksheet, such as its name, index, size (row and column counts), current active cell, and selected range. Returns null if no active worksheet is available.
78+
79+
**Retrieve the active worksheet**
80+
81+
This approach fetches the worksheet that is currently active (selected), enabling access to its properties or performing operations programmatically (for example, reading its name or ID, or using it as a context for further actions).
7882

7983
{% tabs %}
8084
{% highlight razor %}
85+
@using Syncfusion.Blazor.Spreadsheet
8186

8287
<button @onclick="GetActiveWorksheet">Get Active Worksheet</button>
83-
8488
<SfSpreadsheet @ref=SpreadsheetInstance DataSource="DataSourceBytes">
8589
<SpreadsheetRibbon></SpreadsheetRibbon>
8690
</SfSpreadsheet>
@@ -101,23 +105,29 @@ Retrieves key properties of the [GetActiveWorksheet](https://help.syncfusion.co
101105
var active = SpreadsheetInstance.GetActiveWorksheet();
102106
}
103107
}
104-
105108
{% endhighlight %}
106109
{% endtabs %}
107110

108-
### Get cell or range data
109111

110-
Retrieves key properties of the [GetData](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_GetData_System_String_), for a single cell or a selected range and returns a map keyed by each cell's address. Each value is a `CellData` built from the corresponding worksheet cell, including value, number format, formatted display text (when a format is applied), wrap state, lock state, optional hyperlink, and computed style. Returns null when the provided address is null or whitespace.
112+
113+
### Get Worksheet Data Programmatically
114+
115+
Use the [GetData](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_GetData_System_String_) method to retrieve data from a worksheet, either from a single cell or a specified range. This API returns key information about each cell in the given address, making it ideal for extracting and processing spreadsheet data programmatically.
116+
117+
**Retrieve cell or range data from an active worksheet**
118+
119+
This method returns a dictionary where each key is a cell's address and its value is a `CellData` object. The returned data includes the raw value, number format, display text (with formatting, if any), wrap/lock status, hyperlink (if applicable), and calculated style. If no cell address is given, or if it is invalid, the result will be null.
111120

112121
| Parameter | Type | Description |
113-
| -- | -- | -- |
114-
| cellAddress | string | Specifies the cell or range to read. Supports A1 addresses (for example, "A1"), ranges (for example, "A2:B5"), or sheet-qualified references (for example, "Sheet1!A1" or "Sheet1!A2:B5"). When a sheet name is specified, data is read from that sheet; otherwise, the active sheet is used. Null or whitespace results in no data being returned. |
122+
| :-- | :-- | :-- |
123+
| cellAddress | string | The address of the cell or range to read. Can use simple A1 (e.g., "A1"), range (e.g., "A2:B5"), or a sheet-qualified reference (e.g., "Sheet1!A2:B5"). If omitted or invalid, returns null. |
115124

116125
{% tabs %}
117126
{% highlight razor %}
118127

119-
<button @onclick="GetData">Get Data</button>
128+
@using Syncfusion.Blazor.Spreadsheet
120129

130+
<button @onclick="GetData">Get Data</button>
121131
<SfSpreadsheet @ref=SpreadsheetInstance DataSource="DataSourceBytes">
122132
<SpreadsheetRibbon></SpreadsheetRibbon>
123133
</SfSpreadsheet>
@@ -138,6 +148,50 @@ Retrieves key properties of the [GetData](https://help.syncfusion.com/cr/blazor
138148
var data = SpreadsheetInstance.GetData("Sheet2!D5:E6");
139149
}
140150
}
151+
{% endhighlight %}
152+
{% endtabs %}
153+
154+
155+
156+
**Get cell or range data**
157+
158+
This method retrieves data for a single cell or a selected range, returning a dictionary where each key is a cell's address and each value is a `CellData` object. This object contains important cell properties like its raw value, number format, formatted display text (if a format is applied), wrap text status, locked status, any hyperlinks (if applicable and not a formula), and computed style. If the `cellAddress` is null or contains only whitespace, this method returns null.
159+
160+
| Parameter | Type | Description |
161+
| :-- | :-- | :-- |
162+
| cellAddress | string | Specifies the cell or range to read. Supports A1 addresses (for example, "A1"), ranges (for example, "A2:B5"), or sheet-qualified references (for example, "Sheet1!A1" or "Sheet1!A2:B5"). If a sheet name is specified, data is read from that sheet; otherwise, the active sheet is used. Null or whitespace results in no data being returned. |
163+
164+
{% tabs %}
165+
{% highlight razor %}
166+
167+
@using Syncfusion.Blazor.Spreadsheet
168+
169+
<button @onclick="GetData">Get Data</button>
170+
<SfSpreadsheet @ref=SpreadsheetInstance DataSource="DataSourceBytes">
171+
<SpreadsheetRibbon></SpreadsheetRibbon>
172+
</SfSpreadsheet>
173+
174+
@code {
175+
public byte[] DataSourceBytes { get; set; }
176+
public SfSpreadsheet SpreadsheetInstance;
177+
178+
protected override void OnInitialized()
179+
{
180+
string filePath = "wwwroot/Sample.xlsx";
181+
DataSourceBytes = File.ReadAllBytes(filePath);
182+
}
183+
184+
public async Task GetData()
185+
{
186+
// Get data for a specific range
187+
var data = SpreadsheetInstance.GetData("Sheet2!D5:E6");
188+
// You can now iterate through `data` to access individual cell information
189+
foreach (var entry in data)
190+
{
191+
Console.WriteLine($"Cell: {entry.Key}, Value: {entry.Value.Value}, DisplayText: {entry.Value.DisplayText}");
192+
}
193+
}
194+
}
141195

142196
{% endhighlight %}
143197
{% endtabs %}

0 commit comments

Comments
 (0)