1. Tag Results
intersect-range (1)
1 - 1 of 1
How to get the intersection of two ranges in Excel worksheet using C#, VB.NET?
Syncfusion Essential® XlsIO is a .NET Excel library used to create, read, and edit Excel documents. It also, converts Excel documents to PDF files. Using this library, you can get the intersection of any two Excel ranges in C# or VB.NET. Steps to get the intersection of two ranges in Excel, programmatically: 1. Create a new C# console application project.  Create a new console application project 2. Install the Syncfusion.XlsIO.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.  Install the XlsIO NuGet package 3. Include the following namespace in the Program.cs file. C# using Syncfusion.XlsIO;   VB.NET Imports Syncfusion.XlsIO   4. Use the following code snippet to get the intersection of two ranges in an Excel worksheet using C# or VB.NET. C# using (ExcelEngine excelEngine = new ExcelEngine()) {     // Instantiate the application object     IApplication application = excelEngine.Excel;       // Open the template workbook with dummy data     IWorkbook workbook = application.Workbooks.Open("TemplateData.xlsx", ExcelOpenType.Automatic);       // Accessing the first worksheet     IWorksheet worksheet = workbook.Worksheets[0];       // Check if the ranges "C1:G10" and "D3:Q6" intersect     IRange intersectRange = worksheet.IntersectRanges(worksheet.Range["C1:G10"], worksheet.Range["D3:Q6"]);     if( intersectRange != null)     {         Console.WriteLine("true");         Console.WriteLine("Intersecting range: " + intersectRange.AddressLocal);         Console.ReadKey();     }     else     {         Console.WriteLine("false");         Console.ReadKey();     } }   VB.NET Using excelEngine As ExcelEngine = New ExcelEngine()     'Instantiate the application object     Dim application As IApplication = excelEngine.Excel       'Open the template workbook with dummy data     Dim workbook As IWorkbook = application.Workbooks.Open("TemplateData.xlsx", ExcelOpenType.Automatic)       'Accessing the first worksheet     Dim worksheet As IWorksheet = workbook.Worksheets(0)       'Check if the ranges "C1:G10" and "D3:Q6" intersect     Dim intersectRange As IRange = worksheet.IntersectRanges(worksheet.Range("C1:G10"), worksheet.Range("D3:Q6"))     If intersectRange IsNot Nothing Then         Console.WriteLine("true")         Console.WriteLine("Intersecting range: " + intersectRange.AddressLocal)         Console.ReadKey()     Else         Console.WriteLine("false")         Console.ReadKey()     End If End Using   A complete working example to find the intersection of two ranges in Excel can be downloaded from Intersection of two ranges in Excel.zip. Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through Formulas, adding Charts in worksheet or workbook, organizing and analyzing data through Tables and Pivot Tables, appending multiple records to worksheet using Template Markers, and most importantly PDF and Image conversions etc. with code examples. Click here to explore the rich set of Syncfusion Excel (XlsIO) library features. See Also: How to update formula for each row using Template Markers Merge Excel cells in C#, VB.NET Paste only the formula value of Excel cell in C#, VB.NET How to set column width and row height? How can we avoid the ‘Unexpected token’ exception while using formula in XlsIO? How to add text box shape in Excel charts? Note:Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering Syncfusion® license key in your application to use the components without a trial message.    ConclusionI hope you enjoyed learning about how to get the intersection of two ranges in Excel worksheet using C#, VB.NET.You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion® components.If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, or feedback portal. We are always happy to assist you!
No articles found
No articles found
1 of 1 pages (1 item)