2.2.4.5.50 Column::SetFormat

Description

Set the column format.

Syntax

BOOL SetFormat( int iFormat, int nSubformat = -1, BOOL bUndo = FALSE, int * pnErr = NULL )


BOOL SetFormat( int iFormat, LPCSTR lpcszCustomFormat, BOOL bUndo = FALSE, int * pnErr = NULL )

Parameters

iFormat
[input] the column format,enum {
OKCOLTYPE_NUMERIC,
OKCOLTYPE_TEXT,
OKCOLTYPE_TIME,
OKCOLTYPE_DATE,
OKCOLTYPE_MONTH,
OKCOLTYPE_WEEKDAY,
OKCOLTYPE_COLUMN,
OKCOLTYPE_DATASET,
OKCOLTYPE_DATASET_X,
OKCOLTYPE_TEXT_NUMERIC,
OKCOLTYPE_CATEGORICAL,
OKCOLTYPE_PERCENTAGE,
OKCOLTYPE_CURRENCY,
OKCOLTYPE_STROBJ }
nSubformat
[input] The integer (enumerated from zero) of the subformat for the current column type, -1 means set format only.
bUndo
[input] if bUndo is true, you can use Ctrl + Z to undo SetFormat.
pnErr (Origin 2025)
[output] get error code. 0 if no error, or 1 if fail to convert text format to the specified format


iFormat
[input] the column format, OKCOLTYPE_*
lpcszCustomFormat
[input] the custom date display string.
bUndo
[input] if bUndo is true, you can use Ctrl + Z to undo SetFormat.
pnErr (Origin 2025)
[output] get error code. 0 if no error, or 1 if fail to convert text format to the specified format

Return

TRUE, set the coloumn format successfully, FALSE, unsuccessful.

Examples

EX1

// Worksheet with at least one column must exist in project
void    Column_SetFormat_Ex1()
{
    WorksheetPage wp = Project.WorksheetPages(0);
    if(!wp)
        return;
    
    Worksheet wks(wp.GetName());
    printf("Format of column %s is of type %u\n", wks.Columns(0).GetName(), wks.Columns(0).GetFormat());
    printf("Setting to Numeric (0)\n");
    BOOL b = wks.Columns(0).SetFormat(OKCOLTYPE_NUMERIC);
    printf("Format of column %s is of type %u\n", wks.Columns(0).GetName(), wks.Columns(0).GetFormat());
}


EX2

void SetFormat_ex1()
{
	Worksheet wks = Project.ActiveLayer();
	Column col(wks, 0);
	col.SetFormat(OKCOLTYPE_DATE, "yyyy'-'MM'-'dd");
}
void SetFormat_ex2()
{
	Worksheet wks = Project.ActiveLayer();
	Column col(wks, 1);
	col.SetFormat(OKCOLTYPE_TEXT_NUMERIC, "DMS2");
}
void SetFormat_ex3()
{
	Worksheet wks = Project.ActiveLayer();
	Column col(wks, 2);
	col.SetFormat(OKCOLTYPE_TIME, "hh mm ss'.'##");
}

EX3

//new a book and paste 15:59:59.995 to first cell of Col(A) and Col(B)
//this example show sometimes setting custom display format directly will fail, then you can use nSubformat instead
void SetFormat_ex()
{
	Worksheet wks = Project.ActiveLayer();	
	int nErr = 0;
	int bRet;
	
	bRet = wks.Columns(0).SetFormat(OKCOLTYPE_TIME, "HH:mm:ss", FALSE, &nErr);
	printf("bRet = %s, nErr = %d\n", bRet?"true":"false", nErr);
	
	bRet = wks.Columns(1).SetFormat(OKCOLTYPE_TIME, LTF_HH_MM_SS, FALSE, &nErr);	
	printf("bRet = %s, nErr = %d\n", bRet?"true":"false", nErr);
}

Remark

Set the column format.

See Also

Column::GetFormat, Column::SetSubFormat
Column::SetCustomDisplay

Header to Include

origin.h