2.2.4.12.4 Datasheet::Create

Description

Create a worksheet from the special template


Create a worksheet from the special template

Syntax

BOOL Create( LPCSTR lpcszTemplate = NULL, int nOption = CREATE_VISIBLE )


BOOL Create( LPCSTR lpcszTemplate, LPCSTR lpcszSheetName, int nOption = CREATE_VISIBLE )

Parameters

lpcszTemplate
[input] The template file name, "" or NULL to use a default template and "0"
to create without template. Its default value is NULL.
nOption
[input] Template and visibility options from enum properties CREATE_TEMP etc (OC_const.h).
Its default value is CREATE_VISIBLE.


lpcszTemplate
[input] The template file name, "" or NULL to use a default template and "0" to create without template
lpcszSheetName
[input] The named sheet to load existing in a multisheet template, or NULL or "" to load the first sheet in a multisheet template
nOption
[input] Template and visibility options from enum properties CREATE_TEMP etc.(OC_const.h).
Its default value is CREATE_VISIBLE.

Return

TRUE for success, otherwise FALSE.


TRUE for success, otherwise FALSE.

Examples

EX1

int    Datasheet_Create_Ex1()
{
    Worksheet    wks;
    if( wks.Create("FFT", CREATE_VISIBLE_SAME) )
        printf("New worksheet %s with FFT template is created\n", wks.GetPage().GetName());
    
    Worksheet    wksNew;
    if(wksNew.Create()) //create with default template
        printf("New worksheet %s with default template is created\n", wksNew.GetPage().GetName()); 
        
    Worksheet    wksNoTemplate;
    if(wksNoTemplate.Create("0", CREATE_HIDDEN))
        printf("New hidden worksheet %s without template is created\n", wksNoTemplate.GetPage().GetName());
    
    MatrixLayer    mat; 
    if(mat.Create(NULL, CREATE_HIDDEN)) //create with default template
        printf("Hidden matrix %s of %d columns by %d rows is created\n", mat.GetPage().GetName(), mat.GetNumCols(), mat.GetNumRows());
    return 0;
}

EX2

// the following example make use of the new CREATE_NO_DEFAULT_TEMPLATE flag introduced for Origin8
int Datasheet_Create_Ex2(BOOL bNoDefaultTemplate = TRUE)
{
    DWORD        dwCntrl = CREATE_VISIBLE; // Page should be visible
    
    if(bNoDefaultTemplate)
        dwCntrl |= CREATE_NO_DEFAULT_TEMPLATE; 
    
    Worksheet    wks;
    BOOL        bResult;
    string        strTemplateName = "bogus_name_that_origin_will_not_find.otw";
    if(bResult = wks.Create(strTemplateName, dwCntrl))
    {
        if(bNoDefaultTemplate)
            printf("Worksheet %s created from template %s\n", wks.GetPage().GetName(), strTemplateName);
        else
            printf("Worksheet %s created.\nNot sure if specified template [%s] was used though, as it may be missing and default was substituded\n", wks.GetPage().GetName(), strTemplateName);
    }
    
    if( !bResult && bNoDefaultTemplate )
        printf("Template [%s] not found, cannot ceate worksheet\n", strTemplateName);
    return (int) bResult;
}

EX3

//Rename the specified created worksheet with new name.
void Datasheet_Creat_Ex3()
{
    Worksheet wks;
    bool bRet = wks.Create("FFT.otw","Sheet1");
    if(bRet)
        wks.SetName("Data1");
}

Remark

Create a new worksheet or matrix using the supplied template and attach it to the object.

Supports selection of a specified layer from multi-layered template with lpcszSheetName. Please note that CREATE_KEEP_LAYER_NAMES

is enforced if lpcszSheetName is specified

See Also

Worksheet::CreateCopy

Header to Include

origin.h