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.

class ColumnCollection;

Example

const { Workbook, Color, BackgroundType, StyleFlag } = require("aspose.cells.node");

//Instantiating a Workbook object
var workbook = new Workbook();
//Obtaining the reference of the first worksheet
var worksheet = workbook.getWorksheets().get(0);
//Add new Style to Workbook
var style = workbook.createStyle();
//Setting the background color to Blue
style.setForegroundColor(Color.Blue);
//setting Background Pattern
style.setPattern(BackgroundType.Solid);
//New Style Flag
var styleFlag = new StyleFlag();
//Set All Styles
styleFlag.setAll(true);

//Change the default width of first ten columns
for (var i = 0; i < 10; i++)
{
    worksheet.getCells().getColumns().get(i).setWidth(20);
}

//Get the Column with non default formatting
var columns = worksheet.getCells().getColumns();
var count = columns.getCount();
for (var i = 0; i < count; i++)
{
    var column = columns.getColumnByIndex(i);
    //Apply Style to first ten Columns
    column.applyStyle(style, styleFlag);
}

//Saving the Excel file
workbook.save("output/ColumnCollection.xls");

Methods

MethodDescription
get(number)Gets a Column object by column index. The Column object of given column index will be instantiated if it does not exist before.
getColumnByIndex(number)Gets the Column object by the position in the list.
getCount()Gets the number of elements contained in.
isNull()Checks whether the implementation object is null.

get(number)

Gets a Column object by column index. The Column object of given column index will be instantiated if it does not exist before.

get(columnIndex: number) : Column;

Parameters:

ParameterTypeDescription
columnIndexnumber

Returns

Column

getColumnByIndex(number)

Gets the Column object by the position in the list.

getColumnByIndex(index: number) : Column;

Parameters:

ParameterTypeDescription
indexnumberThe position in the list.

Returns

Returns the column object.

getCount()

Gets the number of elements contained in.

getCount() : number;

isNull()

Checks whether the implementation object is null.

isNull() : boolean;