| Worksheet::AddColAddCol DescriptionAdd a new column to the worksheet. If the specified name is already used by an existing column then the new column's name will be enumerated. Syntax
int AddCol( LPCSTR lpcszColName = NULL, BOOL bUndo = FALSE )
   
int AddCol( LPCSTR lpcszColName, string & strColNameCreated, BOOL bUndo = FALSE )
 Parameters
    lpcszColName[input] The name to be given to the new column. Use "" or NULL to use a default name. If a name is specified and it is already the name of an existing column then the specified name is enumerated.bUndo[input] Allow this action to be undone from the Origin GUI.   
    lpcszColName[input] The name to be given to the new column. Use "" or NULL to use a default name. If a name is specified and it is already the name of an existing column then the specified name is enumerated.strColNameCreated[output] String to store the actual column name on return.bUndo[input] Allow this action to be undone from the Origin GUI. ReturnIf the method succeeds, the return value is the zero-based index of the newly added column. If the method fails, the return value is -1. ExamplesEX1 
// Add two sets of X,Y columns to the active worksheet in the first workbook.
int Worksheet_AddCol_Ex1()
{
    // Get first workbook.
    WorksheetPage wp = Project.WorksheetPages(0);
    if(!wp)
        return -1;
    // Get the workbook's active worksheet.
    Worksheet wks(wp.GetName());
    string strBase = "Temp";
    int iLastColumnAdded;
    for( int iNum = 1 ; iNum <= 2 ; iNum++ )
    {
        iLastColumnAdded = wks.AddCol();
        wks.Columns(iLastColumnAdded).SetType(OKDATAOBJ_DESIGNATION_X);
        iLastColumnAdded = wks.AddCol(strBase + iNum);
    }
    return iLastColumnAdded;
}
EX2
 
int Worksheet_AddCol_Ex2()
{
    // Get first workbook.
    WorksheetPage wp = Project.WorksheetPages(0);
    if(!wp)
        return -1;
    
    // Get the workbook's active worksheet.
    Worksheet wks(wp.GetName());
    string str;
    int iStatus = 0;
    int iCol;
    
    // Add first Y column to the active worksheet in the first workbook.
    iCol = wks.AddCol("NewCol", str);
    if(iCol >= 0)
        printf("New column created at index %d, named %s\n", iCol, str);
    else
        iStatus++;
    // Add second Y column to the active worksheet in the first workbook.
    iCol = wks.AddCol("NewCol", str);
    if(iCol >= 0)
        printf("New column created at index %d, named %s\n", iCol, str);
    else
        iStatus++;
    return iStatus;
}
RemarkAdd a new column to the worksheet with the given name and store the name in a string. If the given name already exists then increase it. See AlsoWorksheet::DeleteCol, Worksheet::InsertCol, Worksheet::SetSize header to Includeorigin.h |