Worksheet.Range Property | .NET File Format Library - C# & VB.NET
Có thể bạn quan tâm
Provides access to the range of cells in the worksheet.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v25.2.Core.dll
Declaration
- C#
- VB.NET
Property Value
| Type | Description |
|---|---|
| IRangeProvider | An object implementing the IRangeProvider interface. |
Remarks
A cell range is a rectangular block of cells that is specified by the CellRange object. You can manipulate cell ranges when you format cells or process data.
The Range property returns the IRangeProvider object. Use the one of the following members to obtain a cell range.
- IRangeProvider.Item, IRangeProvider.Parse - obtain a cell range by its cell reference or name.
- IRangeProvider.FromLTRB - obtains a cell range by the indexes of its top left and bottom right cells.

Use the following properties and methods to work with cell ranges.
Operation | Members | Read More… |
|---|---|---|
Get Cell Reference | CellRange.GetReferenceA1 CellRange.GetReferenceR1C1 | Cell Referencing |
Format Cell Ranges | CellRange.Style CellRange.BeginUpdateFormatting - CellRange.EndUpdateFormatting CellRange.FillColor, Formatting.Fill Formatting.Font Formatting.NumberFormat Formatting.Alignment Formatting.Borders, CellRange.SetInsideBorders | How to: Format Cells |
Set Values or Formulas to Cells | CellRange.Value CellRange.Formula, CellRange.ArrayFormula, CellRange.HasArrayFormula | Cell Data Types Spreadsheet Formulas How to: Change a Cell or Cell Range Value How to: Add Formulas to Cells |
Add Hyperlinks to Cells | Worksheet.Hyperlinks HyperlinkCollection.Add HyperlinkCollection.GetHyperlinks | How to: Add a Hyperlink to a Cell |
Add Comments to Cells | Worksheet.Comments CommentCollection.Add CommentCollection.GetComments | Comments |
Name Cells | CellRange.Name Worksheet.DefinedNames, DefinedNameCollection.Add | Defined Names How to: Create a Named Range of Cells |
Merge Cells | Worksheet.MergeCells, Worksheet.UnMergeCells | How to: Merge Cells or Split Merged Cells |
Copy Cells | CellRange.CopyFrom | How to: Copy Cell Data Only, Cell Style Only, or Cell Data with Style |
Clear Cells | Worksheet.Clear Worksheet.ClearContents Worksheet.ClearFormats Worksheet.ClearComments Worksheet.ClearHyperlinks | How to: Clear Cells of Content, Formatting, Hyperlinks and Comments |
Insert Cells | Worksheet.InsertCells | How to: Insert a Cell or Cell Range |
Delete Cells | Worksheet.DeleteCells | How to: Delete a Cell or Range of Cells |
Obtain Intersection of Cell Ranges | CellRange.IsIntersecting CellRange.Intersect | |
Create a Complex Range | CellRange.Union |
Example
This example demonstrates how to access ranges of cells in a worksheet. There are several ways to accomplish this.
- The Worksheet.Item property obtains cell ranges defined by a cell reference (using A1 style) or a defined name.
- Ranges defined by a cell reference (using R1C1 or other reference styles), a defined name in a workbook, or by indexes of the bounding rows and columns - use the IRangeProvider.Item, IRangeProvider.Parse and IRangeProvider.FromLTRB members. Access the IRangeProvider object by the Worksheet.Range or IWorkbook.Range property.
View Example
- CellActions.cs
- CellActions.vb
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Range property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
- C#
- VB.NET
winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/CS/SpreadsheetControl/SpreadsheetActions/ConditionalFormatting.cs#L38
// Create the rule highlighting values that are above the average in cells C2 through C15. AverageConditionalFormatting cfRule1 = conditionalFormattings.AddAverageConditionalFormatting(worksheet.Range["$C$2:$C$15"], ConditionalFormattingAverageCondition.AboveOrEqual); // Specify formatting options to be applied to cells if the condition is true.wpf-spreadsheet-how-to-apply-conditional-formatting-to-a-range-of-cells/CS/ConditionalFormatting_WPF_Examples/SpreadsheetActions/ConditionalFormatting.cs#L37
// Create the rule highlighting values that are above the average in cells C2 through C15. AverageConditionalFormatting cfRule1 = conditionalFormattings.AddAverageConditionalFormatting(worksheet.Range["$C$2:$C$15"], ConditionalFormattingAverageCondition.AboveOrEqual); // Specify formatting options to be applied to cells if the condition is true.spreadsheet-document-api-apply-conditional-formatting-to-cell-range/CS/ConditionalFormatting_Example/SpreadsheetActions/ConditionalFormatting.cs#L55
// Add an explanation to the created rule. CellRange ruleExplanation = worksheet.Range["A17:G18"]; ruleExplanation.Value = "Determine cost values that are above the average in the first quarter and one standard deviation below the mean in the second quarter.";spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/DocumentPropertiesActions.cs#L22
CellRange header = worksheet.Range["B2:C2"]; header[0].Value = "Property Name";winforms-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_API_Part02/SpreadsheetActions/DocumentPropertiesActions.cs#L23
CellRange header = worksheet.Range["B2:C2"]; header[0].Value = "Property Name";winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/VB/SpreadsheetControl/SpreadsheetActions/ConditionalFormatting.vb#L37
' Create the rule highlighting values that are above the average in cells C2 through C15. Dim cfRule1 As AverageConditionalFormatting = conditionalFormattings.AddAverageConditionalFormatting(worksheet.Range("$C$2:$C$15"), ConditionalFormattingAverageCondition.AboveOrEqual) ' Specify formatting options to be applied to cells if the condition is true.wpf-spreadsheet-how-to-apply-conditional-formatting-to-a-range-of-cells/VB/ConditionalFormatting_WPF_Examples/SpreadsheetActions/ConditionalFormatting.vb#L35
' Create the rule highlighting values that are above the average in cells C2 through C15. Dim cfRule1 As AverageConditionalFormatting = conditionalFormattings.AddAverageConditionalFormatting(worksheet.Range("$C$2:$C$15"), ConditionalFormattingAverageCondition.AboveOrEqual) ' Specify formatting options to be applied to cells if the condition is true.spreadsheet-document-api-apply-conditional-formatting-to-cell-range/VB/ConditionalFormatting_Example/SpreadsheetActions/ConditionalFormatting.vb#L60
' Add an explanation to the created rule. Dim ruleExplanation As CellRange = worksheet.Range("A17:G18") ruleExplanation.Value = "Determine cost values that are above the average in the first quarter and one standard deviation below the mean in the second quarter."spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/DocumentPropertiesActions.vb#L22
worksheet("E6").Value = "Mike Hamilton" Dim header As CellRange = worksheet.Range("B2:C2") header(0).Value = "Property Name"wpf-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/DocumentPropertiesActions.vb#L19
Dim header As CellRange = worksheet.Range("B2:C2") header(0).Value = "Property Name" See Also How to: Access a Range of Cells How to: Access a Cell in a Worksheet How to: Access a Row or Column Worksheet Interface Worksheet Members DevExpress.Spreadsheet NamespaceTừ khóa » Visual Studio Excel Range
-
Worksheet.Range Property (Microsoft.Office.Tools.Excel)
-
Work With Ranges - Visual Studio (Windows) - Microsoft Docs
-
Range Object (Excel) | Microsoft Docs
-
How To: Programmatically Apply Color To Excel Ranges - Visual Studio ...
-
Range Interface (Microsoft.Office.Interop.Excel)
-
How To Select Cells Or Ranges By Using Visual Basic Procedures In ...
-
How To: Programmatically Refer To Worksheet Ranges In Code
-
WorksheetBase.Range Property (Microsoft.Office.Tools.Excel)
-
How To: Programmatically Apply Color To Excel Ranges - Microsoft Docs
-
C# - Fastest Way To Get An Excel Range Of Rows - Stack Overflow
-
C# Excel Range Code Example (Without Using Interop) | IronXL
-
Working With Range Object In Excel Add In - Visual Studio Feedback
-
How To Read An Excel File Using C#
-
How To Manage Excel Ranges Using Visual Basics - Universal Class