- Document Solutions for Excel, .NET Edition Overview
- Key Features
- Getting Started
-
Features
-
Worksheet
- Work with Worksheets
-
Range Operations
- Access a Range
- Get Intersection, Union and Offset Range
- Access Areas in a Range
- Get Range and Range Area
- Get Special Cell Ranges
- Access Cells, Rows and Columns in a Range
- Get Address of Cell Range
- Cut or Copy Cell Ranges
- Cut or Copy Shape, Slicer, Chart and Picture
- Paste or Ignore Data in Hidden Range
- Find and Replace Data
- Get Row and Column Count
- Hide Rows and Columns
- Insert And Delete Cell Ranges
- Insert and Delete Rows and Columns
- Merge Cells
- Auto Merge Cells
- Protect Cell Range
- Set Values to a Range
- Set Custom Objects to a Range
- Set Row Height and Column Width
- Auto Fit Row Height and Column Width
- Work with Used Range
- Measure Digital Width
- Set Default Values for Cell Range
- Set Cell Background Image for Cell Range
- Ignore Errors in Cell Range
- Customize Worksheets
- Worksheet Views
- Cell Types
- Quote Prefix
- Tags
- Rich Text
- Background Image
- Workbook
- Comments
- Hyperlinks
- Sort
- Filter
- Group
- Conditional Formatting
- Data Validations
- Data Binding
- Import Data
- Digital Signatures
- Formulas
- Custom Functions
- Shapes
- Document Properties
- Styles
- Form Controls
- Barcodes
- Themes and Colors
- Chart
- Table
- Pivot Table
- Pivot Chart
- Sparkline
- Slicer
- Logging
- Defined Names
-
Worksheet
- Templates
- File Operations
- Document Solutions Data Viewer
- API Reference
- Release Notes
(Showing Draft Content)
Get Range and Range Area
Range or a range area refers to an array of cells that have been defined in a spreadsheet. While working with worksheets in a workbook, users can define multiple ranges and then further access those range areas separately to perform certain tasks like formatting of cells, merging of cells, insertion or deletion of cells within a range and other useful operations.
Refer to the following example code to see how you can define a range.
//Use index to access cell A1.
worksheet.Range[0, 0].Interior.Color = Color.LightGreen;
//Use index to access range A1:B2
worksheet.Range[0, 0, 2, 2].Value = 5;
//Use string to access range.
worksheet.Range["A2"].Interior.Color = Color.LightYellow;
worksheet.Range["C3:D4"].Interior.Color = Color.Tomato;
worksheet.Range["A5:B7, C3, H5:N6"].Value = 2;
//Use index to access rows
worksheet.Rows[2].Interior.Color = Color.LightSalmon;
//Use string to access rows
worksheet.Range["4:4"].Interior.Color = Color.LightSkyBlue;
//Use index to access columns
worksheet.Columns[2].Interior.Color = Color.LightSalmon;
//Use string to access columns
worksheet.Range["D:D"].Interior.Color = Color.LightSkyBlue;
//Use Cells to access range.
worksheet.Cells[5].Interior.Color = Color.LightBlue;
worksheet.Cells[5, 5].Interior.Color = Color.LightYellow;
//Access all rows in worksheet
var allRows = worksheet.Rows.ToString();
//Access all columns in worksheet
var allColumns = worksheet.Columns.ToString();
//Access the entire sheet range
var entireSheet = worksheet.Cells.ToString();Refer to the following example code to see how you can access the range area with a range.
//area1 is A5:B7.
var area1 = worksheet.Range["A5:B7,C3,H5:N6"].Areas[0];
//set interior color for area1
area1.Interior.Color = Color.Pink;
//area2 is C3.
var area2 = worksheet.Range["A5:B7,C3,H5:N6"].Areas[1];
//set interior color for area2
area2.Interior.Color = Color.LightGreen;
//area3 is H5:N6.
var area3 = worksheet.Range["A5:B7,C3,H5:N6"].Areas[2];
//set interior color for area3
area3.Interior.Color = Color.LightBlue;