# Get Intersection, Union and Offset Range

DsExcel is a Document Solutions product that offers a comprehensive library to create, manipulate, convert, and share Microsoft Excel-compatible spreadsheets.

## Content

DsExcel allows you to get the intersection, union and offset of specified ranges using the [IRange](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IRange.html) interface.
To get the intersection and union of two or more ranges, you can use [Intersect](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IRange.Intersect.html) method and [Union](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IRange.Union.html) method of the IRange interface respectively. Similarly, the interface also provides [Offset](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IRange.Offset.html) 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:

```csharp
// 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;
```

![](https://cdn.mescius.io/document-site-files/images/e333ad47-35da-43f9-a389-25433765f491/images/intersection.png)

```csharp
// 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);
```

![](https://cdn.mescius.io/document-site-files/images/e333ad47-35da-43f9-a389-25433765f491/images/union.png)

```csharp
// Set the offset of the range value and style.
var offsetRange = worksheet.Range["B2:D4"].Offset(4, 4);
offsetRange.Merge();
offsetRange.Value = "Offset Range";
```

![](https://cdn.mescius.io/document-site-files/images/e333ad47-35da-43f9-a389-25433765f491/images/offset.png)

> !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](https://developer.mescius.com/documents-api-excel/demos/rangeintersectandunion), and [Offset](https://developer.mescius.com/documents-api-excel/demos/rangeoffset) Demo sample.