Introduction
We have discussed about working with worksheets, rows and columns so far but this is the time to go more deeper and talk about cells. So, in this topic, we would start our discussion about cells with a basic feature of Aspose.Grid.Web about accessing cells.
Accessing Cells in a Worksheet
Each worksheet contains a WebCells object, which is a collection of WebCell objects. A WebCell object represents a cell in Aspose.Grid.Web. We can access any cell of a worksheet using the API of Aspose.Grid.Web. There are two preffered ways to access cells as follows:
- Using Cell Name
- Using Cell's Row & Column Indices
Let's discuss above two approaches one by one.
Using Cell Name
All cells in a worksheet have a unique name. For example, A1, A2, B1, B2 etc. Aspose.Grid.Web allows developers to access any desired cell by using its cell name. All we have to do is to just pass the cell name (as an index) to the Cells collection of the WebWorksheet.
Example:
[C#]
//Accessing the worksheet of the Grid that is currently active
WebWorksheet sheet=GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];
//Accessing "B1" cell of the worksheet
WebCell cell=sheet.Cells["B1"];
[VB.NET]
'Accessing the worksheet of the Grid that is currently active
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(GridWeb1.ActiveSheetIndex)
'Accessing "B1" cell of the worksheet
Dim cell as WebCell=sheet.Cells("B1")
Using Cell's Row & Column Indices
A cell in a worksheet can also be recognized using its location in terms of its row and column indices. All we have to do is to just pass the row and column indices of the cell to the Cells collection of the WebWorksheet. This approach is more faster than the above one.
Example:
[C#]
//Accessing the worksheet of the Grid that is currently active
WebWorksheet sheet=GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];
//Accessing "B1" cell of the worksheet using its row and column indices
WebCell cell=sheet.Cells[0,1];
[VB.NET]
'Accessing the worksheet of the Grid that is currently active
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(GridWeb1.ActiveSheetIndex)
'Accessing "B1" cell of the worksheet using its row and column indices
Dim cell As WebCell = sheet.Cells(0,1)