Version

Accessing Cells and Regions by their Reference Strings

This topic will familiarize you on how to access cells and ranges within a worksheet in an Excel® Workbook. The GetCell and GetRegion method of the Worksheet class accepts cell reference strings as a parameter.

In the following example code a Worksheet cell is accessed by the GetCell method and an Excel formula is applied to it. Similarly an Excel formula is applied to a range of cells within the worksheet.

In Visual Basic:

'Accessing a single cell
worksheet.GetCell ("C5").ApplyFormula ("=A5*B5")
'Accessing a range of cells
 worksheet.GetRegion ("G1:G10").ApplyFormula ("=E1*F1")

In C#:

//Accessing a single cell
worksheet.GetCell ("C5").ApplyFormula ("=A5*B5");
//Accessing a range of cells
 worksheet.GetRegion ("G1:G10").ApplyFormula ("=E1*F1");