2.2.4.46.92 Worksheet::Sort

Description

Sort the specified columns in a worksheet in ascending or descending order based on the values in the specified column number. All column and row numbers are 0 based offsets.

Syntax

BOOL Sort(	int wByColNum = 0,
		BOOL wOrder = SORT_ASCENDING,
		BOOL bMissingValuesSmall = TRUE,
		int iFromRow = 0,
		int iFromCol = 0,
		int iToRow = -1,
		int iToCol = -1,
		BOOL bUndo = FALSE,
                BOOL bStableSort = FALSE )


BOOL Sort(	const vector<int>& vSortByCols,
		const vector<BOOL>& vOrder,
		BOOL bMissingValuesSmall = TRUE,
		int iFromRow = 0,
		int iFromCol = 0,
		int iToRow = -1,
		int iToCol = -1,
		BOOL bUndo = FALSE,
                BOOL bStableSort = FALSE )
BOOL Sort(	const vector<int>& vSortByCols,
		const vector<BOOL>& vOrder,
		const vector<int>& vColsBegin,
		const vector<int>& vColsEnd,
		int iFromRow = 0,
		int iToRow = -1,
		BOOL bMissingValuesSmall = TRUE,
		BOOL bUndo = FALSE,
                BOOL bStableSort = FALSE )

Parameters

wByColNum
[input] Input column number containing values to sort worksheet by. default is 0.
wOrder
[input] Input sort order, possible values are SORT_ASCENDING or SORT_DESCENDING. default is SORT_ASCENDING.
bMissingValuesSmall
[input] Input flag specifies whether missing values are considered to be the smallest(TRUE) or largest possible value(FALSE). default is TRUE.
iFromRow
[input] Input first row number to sort. default is 0.
iFromCol
[input] Input first column number to sort. default is 0.
iToRow
[input] Input last row number to sort, default -1 sorts to last row
iToCol
[input] Input last column number to sort, default -1 sorts to last column
bUndo
[input] Support undo or not.
bStableSort
Use stable arithmetic or not
vSortByCols
[input] Column numbers containing values to sort worksheet by, first element contains column number of primary sort key, etc.
vOrder
[input] Sort orders, possible values are SORT_ASCENDING or SORT_DESCENDING, first element contains sort order of primary sort key, etc.
bMissingValuesSmall
[input] Input flag specifies whether missing values are considered to be the smallest(TRUE) or largest possible value(FALSE). default is TRUE.
iFromRow
[input] Input first row number to sort, default is 0.
iFromCol
[input] Input first column number to sort, default is 0.
iToRow
[input] Input last row number to sort, default -1 sorts to last row
iToCol
[input] Input last column number to sort, default -1 sorts to last column
vColsBegin
[input] For non-contiguous column selections. The index of begin column in one range.
vColsEnd
[input] For non-contiguous column selections. The index of end column in one range.

Return

Returns TRUE on successful exit and FALSE on error.


Returns TRUE on successful exit and FALSE on error.

Examples

EX1

// This example sorts column B in a worksheet in descending order, and missing values are 
// treated as smallest.
void Worksheet_Sort_Ex1()
{
	Worksheet wks = Project.ActiveLayer();
	if (wks.Sort(1,SORT_DESCENDING))
		out_str("Sort successful!");
	else
		out_str("Sort error!");
}


EX2

void Worksheet_Sort_Ex2() 
{
	// nested sort example
	Worksheet wks = Project.ActiveLayer();
	vector<int> vCol = {0,1,2};
	vector<int> vSort = {SORT_ASCENDING, SORT_DESCENDING, SORT_DESCENDING};
	if (wks.Sort(vCol, vSort)) 
		out_str("Sort successful!");
	else
		out_str("Sort error!");
}

Remark

See Also

vectorbase::Sort

Header to Include

origin.h