[]
        
(Showing Draft Content)

GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager

Class: NamedCellTemplatesManager

Sheets.NamedCellTemplates.NamedCellTemplatesManager

Table of contents

Constructors

Methods

Constructors

constructor

new NamedCellTemplatesManager()

Represents a manager for named cell templates. Stores and retrieves cell configuration templates that can be applied to cells.

Methods

add

add(name, template): void

Add a new named template. If name exists, overwrites the old template.

example

var template = {
    style: { backColor: 'red', foreColor: 'white' },
    dataValidations: [{ type: 1, comparisonOperator: 6, condition: { expected: [1, 100] } }]
};
workbook.namedCellTemplates.add('myTemplate', template);

Parameters

Name Type Description
name string The unique name for this template.
template INamedCellTemplate The template definition.

Returns

void


all

all(): INamedCellTemplate[]

Get all templates.

example

var templates = workbook.namedCellTemplates.all();
templates.forEach(function(template) {
    console.log(template.name);
});

Returns

INamedCellTemplate[]

Array of all templates (copies).


clear

clear(): void

Clear all templates.

example

workbook.namedCellTemplates.clear();

Returns

void


createFromCell

createFromCell(name, sheet, row, col, templateOptions?): void

Create a template from an existing cell's configuration.

example

var sheet = spread.getActiveSheet();
// Create a template from cell A1 with all properties
workbook.namedCellTemplates.createFromCell('cellTemplate', sheet, 0, 0);
// Create a template from cell B2 with only style
workbook.namedCellTemplates.createFromCell('styleOnly', sheet, 1, 1, { style: true, conditionalFormat: false, dataValidation: false, cellState: false });

Parameters

Name Type Description
name string The unique name for this template.
sheet Worksheet The worksheet containing the cell.
row number The row index of the cell.
col number The column index of the cell.
templateOptions? ICellTemplateOptions -

Returns

void


get

get(name): null | INamedCellTemplate

Get a template by name. Returns a copy of the template.

example

var template = workbook.namedCellTemplates.get('myTemplate');
if (template) {
    console.log(template.style);
}

Parameters

Name Type Description
name string The name of the template to retrieve.

Returns

null | INamedCellTemplate

The template or null if not found.


has

has(name): boolean

Check whether a template with the given name exists.

example

if (workbook.namedCellTemplates.has('myTemplate')) {
    console.log('Template exists');
}

Parameters

Name Type Description
name string The name of the template to check.

Returns

boolean

True if the template exists, false otherwise.


remove

remove(name): null | INamedCellTemplate

Remove a template by name.

example

var removedTemplate = workbook.namedCellTemplates.remove('myTemplate');
if (removedTemplate) {
    console.log('Template removed:', removedTemplate.name);
}

Parameters

Name Type Description
name string The name of the template to remove.

Returns

null | INamedCellTemplate

The removed template or null if not found.