Set the column format.
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 )
TRUE, set the coloumn format successfully, FALSE, unsuccessful.
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); }
Set the column format.
origin.h