Column Format
Version Info
Minimum Origin Version Required: Origin8 SR0
Get Column Type
You can use Column::GetType to get the type designator of a column.
Set Column Type
This example shows how to Set the type of column in worksheet.
void column_set_type()
{
Worksheet wks;
wks.Create("Origin", CREATE_VISIBLE);
wks.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X); // An X column
wks.AddCol();
wks.Columns(2).SetType(OKDATAOBJ_DESIGNATION_Y); // A Y column
// Note that sequence is forced by internal check that won't allow X Err without Y column in worksheet
wks.Columns(1).SetType(OKDATAOBJ_DESIGNATION_X_ERROR); // An X Err column
wks.AddCol();
wks.Columns(3).SetType(OKDATAOBJ_DESIGNATION_ERROR); // A Y Err column
wks.AddCol();
wks.Columns(4).SetType(OKDATAOBJ_DESIGNATION_L); // A Label column
wks.AddCol();
wks.Columns(5).SetType(OKDATAOBJ_DESIGNATION_Z); // A Z column
wks.AddCol();
wks.Columns(6).SetType(OKDATAOBJ_DESIGNATION_NONE); // A Disregard column
}
Get Column Format
You can use Column::GetFormat to get the type of format of a column.
Set Column Format
This example shows how to set the format of column in worksheet.
void column_set_format_ex()
{
Worksheet wks;
wks.Create("Origin");
//set the format of column 1 as Numeric
BOOL bRet = wks.Columns(0).SetFormat(OKCOLTYPE_NUMERIC);
if( bRet )
printf("Format of column %s is of type %u\n", wks.Columns(0).GetName(), wks.Columns(0).GetFormat());
else
printf("Failed to set format of column %s!\n", wks.Columns(0).GetName());
//set the format of column 2 as text
bRet = wks.Columns(1).SetFormat(OKCOLTYPE_TEXT);
if( bRet )
printf("Format of column %s is of type %u\n", wks.Columns(0).GetName(), wks.Columns(0).GetFormat());
else
printf("Failed to set format of column %s!\n", wks.Columns(0).GetName());
}
Get Column SubFormat
You can use Column::GetSubFormat to get the type of subformat of a column.
Set Column SubFormat
This example shows how to set the subformat of column in worksheet.
void column_set_subformat_ex()
{
Worksheet wks;
wks.Create("Origin");
wks.Columns(0).SetFormat(OKCOLTYPE_DATE); // Column Format is DATE
BOOL bRet = wks.Columns(0).SetSubFormat(13); // The 14th SubFormat (value = 13) of DATE is yyMMdd HH:mm:ss
wks.Columns(1).SetFormat(OKCOLTYPE_NUMERIC); // Column Format is NUMERIC
bRet = wks.Columns(1).SetSubFormat(3); // The 4th SubFormat (value = 3) of NUMERIC is Decimal: 1,000
}
Set Column Justification
This example shows how to set justification of a column. Please refer to Column::SetJustify for more details.
//Before running this code, Worksheet with at least one column must exist in project.
void column_set_justify_ex()
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("Error. Please active worksheet before running!");
return;
}
if( 0 == wks.GetNumCols())
{
printf("Error. No columns to justify in the active worksheet!\n");
return;
}
int iJustify = COL_JUSTIFY_RIGHT;
bool bRet = wks.Columns(0).SetJustify(iJustify); // Set justification to right for column 1
if( bRet )
printf("Successfully set justify!\n");
else
printf("Failed to set justify!\n");
}
Set Column Internal Data Type
This example shows how to set the column internal data type. Please refer to DataObject::SetInternalDataType for more details.
void column_set_internal_data_ex()
{
Worksheet wks = Project.ActiveLayer();
int nFormat = OKCOLTYPE_NUMERIC;
int nType = FSI_SHORT;
foreach(Column col in wks.Columns)
{
col.SetFormat(nFormat);
col.SetInternalDataType(nType, OCD_RESET_VIEW | OCD_RESTORE);
}
}
Set Column Digit Mode
This example shows how to set the display mode used for numbers in a column. Please refer to Column::GetDigitMode for more details.
//Before running this code, Worksheet with at least one column must exist in project.
void column_set_digit_mode_ex()
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("Error. Please active worksheet before running!");
return;
}
if( 0 == wks.GetNumCols())
{
printf("Error. No columns exist in the active worksheet!\n");
return;
}
int iDigitMode = DIGITS_DECIMAL; // set display mode decimal
bool bRet = wks.Columns(0).SetDigitMode(iDigitMode); // Set the display mode of column 1
if( bRet )
printf("Successfully set display mode for column %s\n", wks.Columns(0).GetName());
else
printf("Failed to set displey mode for column %s\n", wks.Columns(0).GetName());
}
Set Column Digit Value
This example shows how to set the digit value for the numeric display mode.
// Before running this code, Worksheet with at least one column must exist in project
void Column_Set_Digits_Ex1()
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("Error. Please active worksheet before running!");
return;
}
if( 0 == wks.GetNumCols())
{
printf("Error. No columns exist in the active worksheet!\n");
return;
}
wks.Columns(0).SetDigitMode(DIGITS_DECIMAL);
bool bRet = wks.Columns(0).SetDigits(10); // set the number of digits in column 1 to 10
if( bRet )
printf("Successfully set digits for column %s\n", wks.Columns(0).GetName());
else
printf("Failed to set digits for column %s\n", wks.Columns(0).GetName());
}
Set Column Custom Display
This example shows how to set the custom date display format. This action is same as setup Custom Date Formats in Preference: Options : Miscellaneous.
// Before running this code, Worksheet with at least one column must exist in project
void column_set_custom_display_ex()
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("Error. Please active worksheet before running!");
return;
}
Column col(wks, 0);
if( col )
{
col.SetFormat(OKCOLTYPE_DATE);
col.SetSubFormat(LDF_OBJ_CUSTOM); // for "Custom Display"
bool bRet = col.SetCustomDisplay("dd-mm-yy");
if( bRet )
printf("The custom display format of Column %u is %s\n", col.GetIndex()+1, col.GetCustomDisplay());
else
printf("Fail to set custom format to this column\n");
}
}
Check Column Is Even Sampling
This example shows how to check if the column has even sampling and get the sampling information.
// Before running this code, Worksheet with at least one column must exist in project
void column_is_even_sampling_ex()
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("Error. Please active worksheet before running!");
return;
}
Column col = wks.Columns(0);
if ( !col )
{
printf("Error. No columns in the active worksheet!\n");
return;
}
double dX0, dXInc; // used to receive the starting X value and the X increment value, if any
string strXUnits, strXLongName; //used to receive the X units name and the X long name, if any
bool bRet = col.IsEvenSampling(&dX0, &dXInc, strXUnits, strXLongName);
if( bRet )
{
printf("Column %s is even sampling.\n", col.GetName());
printf("Start == %f\nIncrement == %f\nUnits == %s\nLong Name == %s\n",
dX0, dXInc, strXUnits, strXLongName); // print the the sampling information
}
else
printf("Column %s is not even sampling.\n", col.GetName());
}
Check Column Is Write Protected
This example shows how to determine if a column is write protected.
// Before running this code, Worksheet with at least one column must exist in project
void column_is_write_protected_ex()
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("Error. Please active worksheet before running!");
return;
}
if( 0 == wks.GetNumCols())
{
printf("Error. No columns in the worksheet!\n");
return;
}
BOOL bRet;
// check each column in the worksheet if it's write protected.
foreach(Column col in wks.Columns)
{
bRet = col.IsWriteProtected();
if( bRet )
printf("Column %s is WRITE PROTECTED\n", col.GetName());
else
printf("Column %s is NOT write protected\n", col.GetName());
}
}
|