Add 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.
int AddCol( LPCSTR lpcszColName = NULL, BOOL bUndo = FALSE )
int AddCol( LPCSTR lpcszColName, string & strColNameCreated, BOOL bUndo = FALSE )
If 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.
EX1
// 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; }
Add 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.
Worksheet::DeleteCol, Worksheet::InsertCol, Worksheet::SetSize
origin.h