Document Solutions for Excel, .NET Edition | Document Solutions
Features / Worksheet / Range Operations / Access Cells, Rows and Columns in a Range
In This Topic
    Access Cells, Rows and Columns in a Range
    In This Topic

    You can access cells, rows and columns in a range by using the Cells property, Rows property and Columns property of the IRange interface.

    Refer to the following example code in order to access cells, rows and columns in a worksheet.

    C#
    Copy Code
    var range = worksheet.Range["A5:B7"];
    
    //Set value for cell A7.
    range.Cells[4].Value = "A7";
    
    //Cell is B6
    range.Cells[1, 1].Value = "B6";
    
    //Row count is 3 and range is A6:B6.
    var rowCount = range.Rows.Count;
    var row = range.Rows[1].ToString();
    
    //Set interior color for row range A6:B6.
    range.Rows[1].Interior.Color = Color.LightBlue;
    
    //Column count is 2 and range is B5:B7.
    var columnCount = range.Columns.Count;
    var column = range.Columns[1].ToString();
    
    //Set values for column range B5:B7.
    range.Columns[1].Interior.Color = Color.LightSkyBlue;
    
    //Entire rows are from row 5 to row 7
    var entirerow = range.EntireRow.ToString();
    
    //Entire columns are from column A to column B
    var entireColumn = range.EntireColumn.ToString();