2.2.4.46.10 Worksheet::CrossTab

Description

Do cross tabulation

Syntax

int CrossTab( int nvRow, int nvCol, int nData, matrix & m, vector<string> * pvsRowVals, vector<string> * pvsColVals, int nStatsType = CT_COUNT, DWORD dwCntrl = 0, LPWksCrossTabMore pMore = NULL )

Parameters

nvRow
[input] the column index of the current worksheet, which is used for the Row variable on the crosstab
nvCol
[input] the column index of the current worksheet, which is used for the column variable on the crosstab
nData
[input] the column index of the current worksheet, which is used for the Data variable on the crosstab
m
[output] the matrix with resulting values, based on nStatsType
pvsRowVals
[output] the name of the Row items get from row variable
pvsColVals
[output] the name of the column items get from column variable
nStatsType
[input] = CT_COUNT, count the records from current worksheet, according to pvsRowVals and pvsColVals.
= CT_SUM, get the sum of the data, which specified by nData, according to pvsRowVals and pvsColVals.
= CT_MIN, get the min of the data, which specified by nData, according to pvsRowVals and pvsColVals.
= CT_MAX, get the max of the data, which specified by nData, according to pvsRowVals and pvsColVals.
= CT_MEAN, get the mean of the data, which specified by nData, according pvsRowVals and pvsColVals.
dwCntrl
[input]options
pMore
[input]Structure of most options
typedef struct tagWksCrossTabMore
{
	const char*		lpcszExtraColumnSource;
	const char*		lpcszExtraRowSource;
}WksCrossTabMore, *LPWksCrossTabMore;

Return

return 0 if successful, <0 if failure

Examples

EX1

//assuming that there is a worksheet, which you want to do the cross tabulation 
void cross_tab_ex1()
{
	Worksheet wks = Project.ActiveLayer();
	MatrixPage mpg;
	mpg.Create("Origin.otm");
	
	MatrixLayer ml = mpg.Layers(0);
	Matrix matResult(ml, 0);
	vector<string>	vsRowVals, vsColVals;
        // do cross tabulation according to column 1 and 2 of current worksheet
        // column 1 as Row variable, and column 2 as Col variable.
	int nRet = wks.CrossTab(1, 2, 0, matResult, &vsRowVals, &vsColVals);
	
	int ii;
	for ( ii = 0; ii < vsRowVals.GetSize(); ii++ )
	{
		out_str(vsRowVals[ii]);
	}
	
	for ( ii = 0; ii < vsColVals.GetSize(); ii++ )
	{
		out_str(vsColVals[ii]);
	}
}

Remark

See Also

Header to Include

origin.h