Click or drag to resize
ExcelColumn Class
Excel column contains column options and cell range with column cells.
Inheritance Hierarchy

Namespace: GemBox.Spreadsheet
Assembly: GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version: 41.3.30.1000
Syntax
public sealed class ExcelColumn : ExcelColumnRowBase

The ExcelColumn type exposes the following members.

Methods
  NameDescription
Public methodAutoFit
Automatically fits column width to the minimum size required for all data in the column to be visible.
Public methodAutoFit(Double)
Automatically fits column width to the minimum size required for all data in the column to be visible.
Public methodAutoFit(Double, ExcelRow, ExcelRow)
Automatically fits column width by checking only the cells in the column that are specified by row range.
Public methodEquals
Determines whether the specified Object is equal to this ExcelColumnRowBase instance.
(Inherited from ExcelColumnRowBase.)
Public methodGetHashCode
Returns a hash code for this ExcelColumnRowBase instance.
(Inherited from ExcelColumnRowBase.)
Public methodGetWidth
Gets the width of column in arbitrary length unit.
Public methodSetWidth
Sets the width of column in arbitrary length unit.
Public methodToString
Returns a String that represents this ExcelColumnRowBase instance.
(Inherited from ExcelColumnRowBase.)
Top
Properties
  NameDescription
Public propertyCode exampleCells
Gets cell range with column / row cells.
(Inherited from ExcelColumnRowBase.)
Public propertyCode exampleCollapsed
Gets or sets whether object is collapsed in outlining.
(Inherited from ExcelColumnRowBase.)
Public propertyHidden
Gets or sets whether excel object is hidden.
(Inherited from ExcelColumnRowBase.)
Public propertyIndex
Gets the row / column zero-based index which represents its position in a worksheet.
(Inherited from ExcelColumnRowBase.)
Public propertyIsStyleDefault Obsolete.
Returns if style is default; otherwise, .
(Inherited from ExcelColumnRowBase.)
Public propertyName
Gets the name of ExcelColumnRowBase instance.
(Inherited from ExcelColumnRowBase.)
Public propertyCode exampleOutlineLevel
Gets or sets outline level.
(Inherited from ExcelColumnRowBase.)
Public propertyCode exampleStyle
Gets or sets the cell formatting of cells in this column / row.
(Inherited from ExcelColumnRowBase.)
Public propertyWidth
Gets or sets column width.
Top
Remarks

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.

Examples

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