Class ColumnCollection

ColumnCollection class

Collection of the Column objects that represent the individual column(setting)s in a worksheet. The Column object only represents the settings such as column width, styles, .etc. for the whole column, has nothing to do with the fact that there are non-empty cells(data) or not in corresponding column. And the “Count” of this collection only represents the count Column objects that have been instantiated in this collection, has nothing to do with the fact that there are non-empty cells(data) or not in the worksheet.

public class ColumnCollection : CollectionBase<Column>

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Gets a Column object by column index. The Column object of given column index will be instantiated if it does not exist before.
Item { get; set; }

Methods

NameDescription
BinarySearch(Column)
BinarySearch(Column, IComparer<Column>)
BinarySearch(int, int, Column, IComparer<Column>)
Clear()
Contains(Column)
CopyTo(Column[])
CopyTo(Column[], int)
CopyTo(int, Column[], int, int)
Exists(Predicate<Column>)
Find(Predicate<Column>)
FindAll(Predicate<Column>)
FindIndex(Predicate<Column>)
FindIndex(int, Predicate<Column>)
FindIndex(int, int, Predicate<Column>)
FindLast(Predicate<Column>)
FindLastIndex(Predicate<Column>)
FindLastIndex(int, Predicate<Column>)
FindLastIndex(int, int, Predicate<Column>)
GetByIndex(int)(Obsolete.) Gets the column object by the index.
GetColumnByIndex(int)Gets the Column object by the position in the list.
GetEnumerator()
IndexOf(Column)
IndexOf(Column, int)
IndexOf(Column, int, int)
LastIndexOf(Column)
LastIndexOf(Column, int)
LastIndexOf(Column, int, int)
RemoveAt(int)

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using System;
    using System.Drawing;

    public class ColumnCollectionDemo
    {
        public static void ColumnCollectionExample()
        {
            // Instantiating a Workbook object
            Workbook workbook = new Workbook();

            // Obtaining the reference of the first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Add new Style to Workbook
            Style style = workbook.CreateStyle();

            // Setting the background color to Blue
            style.ForegroundColor = Color.Blue;

            // Setting Background Pattern
            style.Pattern = BackgroundType.Solid;

            // New Style Flag
            StyleFlag styleFlag = new StyleFlag();

            // Set All Styles
            styleFlag.All = true;

            // Change the default width of first ten columns
            for (int i = 0; i < 10; i++)
            {
                worksheet.Cells.Columns[i].Width = 20;
            }

            // Get the Column with non-default formatting
            ColumnCollection columns = worksheet.Cells.Columns;

            foreach (Column column in columns)
            {
                // Apply Style to first ten Columns
                column.ApplyStyle(style, styleFlag);
            }

            // Saving the Excel file
            workbook.Save("ColumnCollectionExample.xlsx");
            workbook.Save("ColumnCollectionExample.pdf");
        }
    }
}

See Also