2.2.4.46.8 Worksheet::Columns

Description

The Collection of all Columns in a Worksheet


Access the Columns collection by index


Access the Columns collection by name

Syntax

Collection<Column> Columns;


Column Columns( int nCol = -1 )


Column Columns( LPCSTR lpcszName )

Parameters

nCol
[input] Column number with zero offset (< 0 refers to *Active* column). default is -1.


lpcszName
[input] Column name

Return

A Column

Examples

EX1

// Access all columns of a worksheet through the Columns collection
// Two means of using the Columns collection are shown
// Worksheet must be active
void Worksheet_Columns_Ex1()
{
    Worksheet wks = Project.ActiveLayer();
    if( wks )
    {
        // Use the foreach keyword to access as a collection
        int ii = 1;
        foreach(Column cc in wks.Columns)
        {
            printf("Col(%d)'s name is %s\n",ii++, cc.GetName()); 
        }
        // Use the index of Columns to access individually
        int    iNumCols = wks.GetNumCols();
        for( ii = 0 ; ii < iNumCols ; ii++ )
            printf("Col(%u) is %s\n", ii + 1, wks.Columns(ii).GetName());
    }
}



EX2

// Test if column name exists in first worksheet in project
// Worksheet must exist in project
// Syntax : val1 = Worksheet_Column_Ex3(Time)
int Worksheet_Columns_Ex3(string strColName)
{
    WorksheetPage wp = Project.WorksheetPages(0);
    if(!wp)
        return -1;
    
    Worksheet wks(wp.GetName());
    return wks.Columns(strColName).IsValid(); // Return 1 if column exists, else 0
}

Remark

Used to call Column member functions directly with a '.' after the function call

See Also

Worksheet::AddCol, Worksheet::DeleteCol, Worksheet::SetSize

Header to Include

origin.h