- 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 Intersection, Union and Offset Range
DsExcel allows you to get the intersection, union and offset of specified ranges using the IRange interface.
To get the intersection and union of two or more ranges, you can use Intersect method and Union method of the IRange interface respectively. Similarly, the interface also provides Offset method to get the offset of a specified range.
The sample code below shows how to get the intersection, union and offset of different ranges:
// Set the intersection of two range value and style.
var intersectRange = worksheet.Range["A2:E6"].Intersect(worksheet.Range["C4:G8"]);
intersectRange.Interior.Color = Color.FromArgb(56, 93, 171);
intersectRange.Merge();
intersectRange.Value = "Intersect Range";
intersectRange.Font.Bold = true;
intersectRange.Font.Color = Color.FromArgb(226, 231, 243);
intersectRange.HorizontalAlignment = HorizontalAlignment.Center;
intersectRange.VerticalAlignment = VerticalAlignment.Center;// Set the union of two range value and font style.
var unionRange = worksheet.Range["A11:D13"].Union(worksheet.Range["D14:G16"]);
unionRange.Value = "Union Range";
unionRange.Font.Bold = true;
unionRange.Font.Color = Color.FromArgb(226, 231, 243);// Set the offset of the range value and style.
var offsetRange = worksheet.Range["B2:D4"].Offset(4, 4);
offsetRange.Merge();
offsetRange.Value = "Offset Range";!type=note
Note: An exception is thrown, if one or more ranges from a different worksheet are specified or the offset set in Offset method is out of bounds.
To view the code in action, see Intersection and Union, and Offset Demo sample.