Documents for Excel, .NET Edition Documentation
Templates / Template Configuration / Global Settings
In This Topic
    Global Settings
    In This Topic

    Global settings, in GcExcel Templates, are the settings which when defined are applied throughout the template. These settings save lots of effort when same properties need to be applied on several fields. Global settings can be applied in all the template layouts and even in multiple worksheets of a workbook.

    The global settings provided by GcExcel template are explained below:

    Global Settings Description Value
    TemplateOptions.KeepLineSize It specifies whether the row height and column width should be kept the same throughout the template

    Type: Boolean

    Value: True

    False (Default Value)

    TemplateOptions.InsertMode It specifies whether to insert extra cells or entire rows and columns when extra space is needed while expanding the template

    Type: String

    Value: Cells (Default Value)

    EntireRowColumn

    Note: The scope of global settings is within a workbook only, which means, that all the worksheets in a workbook will apply the global settings.

    The global settings can be applied in GcExcel template by using either of the two ways explained below:

    Define Global Settings in Template Layout

    Global settings can be defined in Template layout in Excel in 'Name Manager' dialog box as shown below. The 'Name Manager' can be accessed by navigating through Formulas tab > Defined Names group, and then clicking the 'Name Manager'.

    Set Global Settings using Code

    The global settings can be defined in GcExcel after loading the Excel template by using built-in workbook defined names TemplateOptions. The Add method of INames interface can be used to apply the global settings. The method takes Name and RefersTo properties as the parameters:

    The value of Name property in built-in defined name is taken as the template global option's name. It is case-sensitive.

    The value of RefersTo property in built-in defined name is taken as the template global option's value. It is case-sensitive.

     

    Refer to the below example code to specify the global settings in template:

    C#
    Copy Code
    Workbook workbook = new Workbook();
    workbook.Open("template.xlsx");
    
    //Init template global settings
    workbook.Names.Add("TemplateOptions.KeepLineSize", "true");
    workbook.Names.Add("TemplateOptions.InsertMode", "EntireRowColumn");
    
    //Add data source
    workbook.AddDataSource("ds", ds);
    
    
    //Invoke to process the template
    workbook.ProcessTemplate();
    
    workbook.Save("report.xlsx");

     The below image shows the Excel report when 'TemplateOptions.KeepLineSize' is set to true:

     

    The below image shows the Excel report when 'TemplateOptions.InsertMode' is set to EntireRowColumn. By doing this, the row height and outline groups of the rows are retained when the template expands.