Class ColumnCollection
Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)
Collection of the Aspose.Cells.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>, IList<column>, ICollection<column>, IEnumerable<column>, ICollection, IEnumerable
Inheritance
object ← CollectionBase<column> ← ColumnCollection
Implements
IList<column>, ICollection<column>, IEnumerable<column>, ICollection, IEnumerable
Inherited Members
CollectionBase<column>.BinarySearch(Column), CollectionBase<column>.BinarySearch(Column, IComparer<column>), CollectionBase<column>.BinarySearch(int, int, Column, IComparer<column>), CollectionBase<column>.Contains(Column), CollectionBase<column>.CopyTo(Column[]), CollectionBase<column>.CopyTo(Column[], int), CollectionBase<column>.CopyTo(int, Column[], int, int), CollectionBase<column>.Exists(Predicate<column>), CollectionBase<column>.Find(Predicate<column>), CollectionBase<column>.FindAll(Predicate<column>), CollectionBase<column>.FindIndex(Predicate<column>), CollectionBase<column>.FindIndex(int, Predicate<column>), CollectionBase<column>.FindIndex(int, int, Predicate<column>), CollectionBase<column>.FindLast(Predicate<column>), CollectionBase<column>.FindLastIndex(Predicate<column>), CollectionBase<column>.FindLastIndex(int, Predicate<column>), CollectionBase<column>.FindLastIndex(int, int, Predicate<column>), CollectionBase<column>.IndexOf(Column), CollectionBase<column>.IndexOf(Column, int), CollectionBase<column>.IndexOf(Column, int, int), CollectionBase<column>.LastIndexOf(Column), CollectionBase<column>.LastIndexOf(Column, int), CollectionBase<column>.LastIndexOf(Column, int, int), CollectionBase<column>.GetEnumerator(), CollectionBase<column>.Clear(), CollectionBase<column>.RemoveAt(int), CollectionBase<column>.OnClearComplete(), CollectionBase<column>.OnClear(), CollectionBase<column>.Capacity, CollectionBase<column>.Count, CollectionBase<column>.InnerList, CollectionBase<column>.this[int], object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
csharp
[C#]
//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("book1.xls");
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Add new Style to Workbook
Dim style As Style = workbook.CreateStyles()
'Setting the background color to Blue
style.ForegroundColor = Color.Blue
'setting Background Pattern
style.Pattern = BackgroundType.Solid
'New Style Flag
Dim styleFlag As New StyleFlag()
'Set All Styles
styleFlag.All = True
'Change the default width of first ten columns
For i As Integer = 0 To 9
worksheet.Cells.Columns(i).Width = 20
Next i
'Get the Column with non default formatting
Dim columns As ColumnCollection = worksheet.Cells.Columns
For Each column As Column In columns
'Apply Style to first ten Columns
column.ApplyStyle(style, styleFlag)
Next column
'Saving the Excel file
workbook.Save("book1.xls")
Properties
this[int]
Gets a Aspose.Cells.Column object by column index. The Column object of given column index will be instantiated if it does not exist before.
public Column this[int columnIndex] { get; }
Property Value
Methods
GetColumnByIndex(int)
Gets the Aspose.Cells.Column object by the position in the list.
public Column GetColumnByIndex(int index)
Parameters
index
int
The position in the list.
Returns
Returns the column object. </column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column></column>