ExcelColumnCollection Class |
Namespace: GemBox.Spreadsheet
The ExcelColumnCollection type exposes the following members.
Name | Description | |
---|---|---|
![]() | Count |
Gets the number of currently allocated elements (dynamically changes when worksheet is modified -- read remarks).
(Inherited from ExcelRowColumnCollectionBaseT.) |
![]() | ItemInt32 |
Gets the column with the specified index.
(Overrides ExcelRowColumnCollectionBaseTItemInt32.) |
![]() ![]() | ItemString |
Gets the row / column with the specified name.
(Inherited from ExcelRowColumnCollectionBaseT.) |
Name | Description | |
---|---|---|
![]() ![]() | ColumnIndexToName |
Converts column index (0, 1, ...) to column name ("A", "B", ...).
|
![]() ![]() | ColumnNameToIndex |
Converts column name ("A", "B", ...) to column index (0, 1, ...).
|
![]() | GetEnumerator |
Returns an enumerator that iterates through the collection.
(Inherited from ExcelRowColumnCollectionBaseT.) |
![]() | InsertCopy(Int32, ExcelColumn) |
Inserts copied column at the specified index.
|
![]() | InsertCopy(Int32, Int32, ExcelColumn) |
Inserts specified number of copied columns at the specified index.
|
![]() | InsertEmpty(Int32) |
Inserts empty column at the specified index.
|
![]() | InsertEmpty(Int32, Int32) |
Inserts specified number of empty columns at the specified index.
|
![]() | Remove(Int32) |
Removes the column with the specified index.
|
![]() | Remove(Int32, Int32) |
Removes specified number of columns starting at the specified index.
|
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.
Following code shows how to get hidden columns and shows how to get number of columns occupied with data.
foreach (ExcelColumn column in ws.Columns) { // Writes hidden columns if (column.Hidden) Console.WriteLine("Column '{0}' is hidden", ExcelColumnCollection.ColumnIndexToName(column.Index)); } // Counts used columns (columns that contain some data) Console.WriteLine("Number of used columns is: {0}", ws.CalculateMaxUsedColumns());