Click or drag to resize
ExcelColumnCollection Class
Collection of excel columns (ExcelColumn).
Inheritance Hierarchy

Namespace: GemBox.Spreadsheet
Assembly: GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version:
public sealed class ExcelColumnCollection : ExcelRowColumnCollectionBase<ExcelColumn>

The ExcelColumnCollection type exposes the following members.

Public methodStatic memberColumnIndexToName
Converts column index (0, 1, ...) to column name ("A", "B", ...).
Public methodStatic memberColumnNameToIndex
Converts column name ("A", "B", ...) to column index (0, 1, ...).
Public methodGetEnumerator
Returns an enumerator that iterates through the collection.
(Inherited from ExcelRowColumnCollectionBaseT.)
Public methodInsertCopy(Int32, ExcelColumn)
Inserts copied column at the specified index.
Public methodInsertCopy(Int32, Int32, ExcelColumn)
Inserts specified number of copied columns at the specified index.
Public methodInsertEmpty(Int32)
Inserts empty column at the specified index.
Public methodInsertEmpty(Int32, Int32)
Inserts specified number of empty columns at the specified index.
Public methodRemove(Int32)
Removes the column with the specified index.
Public methodRemove(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());
See Also