GemBox.Spreadsheet ExcelWorksheet
Namespace: GemBox.Spreadsheet
Assembly: GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version: 37.3.30.1035
public sealed class ExcelWorksheet
Worksheet in Microsoft Excel has limited size. Number of rows (ExcelRow) is limited to ExcelFile.MaxRows. Number of columns (ExcelColumn) is limited to ExcelFile.MaxColumns. A specific cell (ExcelCell) can be accessed either trough ExcelRow.Cells, ExcelColumn.Cells or ExcelWorksheet.Cells property. Whichever property used, there are two distinct methods of getting a cell reference; using name and using index. For example, full name of cell in top left corner of a worksheet is "A1". Translated to indexes, same cell would be 0,0 (zero row and zero column). If using ExcelRow.Cells or ExcelColumn.Cells to access a specific cell, only partial name or partial index must be used, providing unknown column or row information.
Note that the cells are internally allocated in rows and not in columns. ExcelColumn objects are created only if they have non-standard width or style, or they are accessed directly. So, while ExcelRowCollection.Count shows number of rows occupied with data, ExcelColumnCollection.Count does not say which Column is the last one occupied with data!
If you want to read all data in a sheet, use ExcelRow.AllocatedCells property.
If you want to find last column occupied with data, use CalculateMaxUsedColumns method.
Look at following code for cell referencing examples:
ExcelWorksheet ws = excelFile.Worksheets.ActiveWorksheet; ws.Cells["B2"].Value = "Cell B2."; ws.Cells[6, 0].Value = "Cell in row 7 and column A."; ws.Rows[2].Cells[0].Value = "Cell in row 3 and column A."; ws.Rows["4"].Cells["B"].Value = "Cell in row 4 and column B."; ws.Columns[2].Cells[4].Value = "Cell in column C and row 5."; ws.Columns["AA"].Cells["6"].Value = "Cell in AA column and row 6.";