Access Worksheet Cells

Accessing Cells in a Worksheet

Each worksheet contains a property by the name of Cells that is actually a collection of GridCell objects where a GridCell object represents a cell in Aspose.Cells.GridWeb. It is possible to access any cell using Aspose.Cells.GridWeb. There are two preferred methods, each of which is discussed below.

Using Cell Name

All cells have a unique name. For example, A1, A2, B1, B2 etc. Aspose.Cells.GridWeb allows developers to access any desired cell by using the cell name. Simply pass the cell name (as an index) to the Cells collection of the GridWorksheet.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the worksheet of the Grid that is currently active
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
// Accessing "A1" cell of the worksheet
GridCell cell = sheet.Cells["A1"];
// Display cell name and value
Label1.Text += "Cell Value of " + cell.Name +" is " + cell.StringValue + "<br/>";

Using Row & Column Indices

A cell can also be recognized by its location in terms of row and column indices. Just pass a cell’s row and column indices to the Cells collection of the GridWorksheet. This approach is more faster than the above one.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the worksheet of the Grid that is currently active
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
// Accessing "B1" cell of the worksheet using its row and column indices
GridCell cell = sheet.Cells[0, 1];
// Display cell name and value
Label1.Text += "Cell Value of " + cell.Name +" is " + cell.StringValue + "<br/>";