Accessing Cells of a Worksheet

Accessing Cells

Aspose.Cells provides a class Workbook that represents an Excel file. The Workbook class contains a Worksheets collection that allows to access each worksheet in the Excel file. A worksheet is represented by the Worksheet class. The Worksheet class provides a Cells collection that represents all cells in the worksheet.

We can use Cells collection to access cells in a worksheet. Aspose.Cells provides three basic approaches to access cells in a worksheet:

  1. Using cell name.
  2. Using a cell’s row and column index.
  3. Using a cell index in the Cells collection

Using Cell Name

Developers can access any specific cell by passing its cell name to the Cells collection of the Worksheet class as an index.

If you create a blank worksheet at start, the count of Cells collection is zero. When you use this approach to access a cell, it will check whether this cell exists in the collection or not. If yes, it returns the cell object in the collection otherwise, it creates a new Cell object, adds the object to the Cells collection and then returns that object. This approach is the easiest way to access the cell if you are familiar with Microsoft Excel but it’s the slowest one as compared to other approaches.

Using Row & Column Index of the Cell

Developers can access any specific cell by passing the indices of its row and column to the Cells collection of the Worksheet class. This approach works in the same way as that of the first approach.

Accessing Maximum Display Range of Worksheet

Aspose.Cells allows developers to access a worksheet’s maximum display range. The maximum display range - the range of cells between the first and last cell with content - is useful when you need to copy, select or display the entire contents of a worksheet in an image.

You can access a worksheet’s maximum display range using MaxDisplayRange method of the Cells collection.