Skip to footer content

How to Select a Range in Excel Using C#

In this tutorial, learn how to select and manipulate cell ranges in Excel using the IronXL library. Begin by setting up a project in Visual Studio and ensure the IronXL library is installed via the NuGet package manager. Import the IronXL namespace in your code. Load an existing Excel file using the Workbook.Load method and access the first worksheet with the Worksheets.First property. To select a specific range of cells, use the indexing syntax like A2:B5. Extract entire rows or columns using the GetRow and GetColumn methods respectively. Combine ranges with the plus operator, demonstrated by merging A2:B5 with A6:B6, and print the combined range to the console. Execute the program to observe the output, showcasing IronXL's capability to simplify Excel manipulation. Explore more of IronXL's functionalities for complex tasks. Visit the website through the link in the description for a trial subscription and experience the powerful features of IronXL.

This code demonstrates how to load an Excel workbook and access a specific worksheet, allowing manipulation of cell ranges. By selecting ranges, extracting rows and columns, and combining cell ranges, you can effectively manage Excel data. The code uses IronXL's simple API to interact with Excel files without needing Excel installed on the machine.

Further Reading: How to Select Range

Regan Pun
Software Engineer
Regan graduated from the University of Reading, with a BA in Electronic Engineering. Before joining Iron Software, his previous job roles had him laser-focused on single tasks; and what he most enjoys at Iron Software is the spectrum of work he gets to undertake, whether it’s adding value to sales, technical support, product development or marketing. He enjoys understanding the way developers are using the Iron Software library, and using that knowledge to continually improve documentation and develop the products.