Worksheet::SortColumns

 

Description

Sort columns by row content.

Syntax

int SortColumns( SortColCtrl* pCtrls, int nCtrlSize, int c1 = 0, int c2 = -1, BOOL bUndo = FALSE )

Parameters

pCtrls
[input] Sort Criterias.
typedef struct tagSortColCtrl
{
int nRow; //label type or row number
DWORD dwCtrl; //SORTCOLUMN_* defined in OC_types.h
LPCSTR lpcszFormat; //row format
}SortColCtrl;
nCtrlSize
[input] number of sort criterias.
c1
[input] Input first column number to sort. default is 0.
c2
[input] Input last column number to sort, default -1 sorts to last column
bUndo
[input] Support undo or not.

Return

Returns 0 on successful exit and negative number on error.

Examples

EX1

void SortColumns_by_label_ex() 
{     
        Worksheet wks = Project.ActiveLayer();
        if(!wks)
                return;
        
        vector<int> vnLabelTypes = {RCLT_LONG_NAME, RCLT_PARAM};
        int nSize = vnLabelTypes.GetSize();    //number of Sort Criteria
        
        int nTotalSize = nSize * sizeof(SortColCtrl);
        SortColCtrl* pCtrls = (SortColCtrl*)malloc(nTotalSize);
        memset(pCtrls, 0, nTotalSize);
        
        for ( int ii=0; ii<nSize; ++ii )
        {
                SortColCtrl* pCtrlCur = pCtrls + ii;
                pCtrlCur->dwCtrl = SORTCOLUMN_BY_LABEL_TYPE;
                pCtrlCur->nRow = vnLabelTypes[ii];          
                
                if(RCLT_PARAM == vnLabelTypes[ii])
                {
                        pCtrlCur->dwCtrl |= SORTCOLUMN_DESCENDING;
                        //with time format
                        pCtrlCur->dwCtrl |= SORTCOLUMN_AS_TIME;                          
                        pCtrlCur->lpcszFormat = "0";//0 = hh:mm, or custom format "hh mm ss'.'##"
                }
        }
        
        wks.SortColumns(pCtrls, nSize);
        
        free(pCtrls);    
                out_str("Sort error!");
}

Remark

See Also

Worksheet::Sort

header to Include

origin.h