# GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager

## Content

# Class: NamedCellTemplatesManager

[Sheets](../modules/GC.Spread.Sheets).[NamedCellTemplates](../modules/GC.Spread.Sheets.NamedCellTemplates).NamedCellTemplatesManager

## Table of contents

### Constructors

- [constructor](GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager#constructor)

### Methods

- [add](GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager#add)
- [all](GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager#all)
- [clear](GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager#clear)
- [createFromCell](GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager#createfromcell)
- [get](GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager#get)
- [has](GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager#has)
- [remove](GC.Spread.Sheets.NamedCellTemplates.NamedCellTemplatesManager#remove)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new NamedCellTemplatesManager**()

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

## Methods

### <a id="add" name="add"></a> add

▸ **add**(`name`, `template`): `void`

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

**`example`**
```javascript
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`](../interfaces/GC.Spread.Sheets.NamedCellTemplates.INamedCellTemplate) | The template definition. |

#### Returns

`void`

___

### <a id="all" name="all"></a> all

▸ **all**(): [`INamedCellTemplate`](../interfaces/GC.Spread.Sheets.NamedCellTemplates.INamedCellTemplate)[]

Get all templates.

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

#### Returns

[`INamedCellTemplate`](../interfaces/GC.Spread.Sheets.NamedCellTemplates.INamedCellTemplate)[]

Array of all templates (copies).

___

### <a id="clear" name="clear"></a> clear

▸ **clear**(): `void`

Clear all templates.

**`example`**
```javascript
workbook.namedCellTemplates.clear();
```

#### Returns

`void`

___

### <a id="createfromcell" name="createfromcell"></a> createFromCell

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

Create a template from an existing cell's configuration.

**`example`**
```javascript
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`](GC.Spread.Sheets.Worksheet) | The worksheet containing the cell. |
| `row` | `number` | The row index of the cell. |
| `col` | `number` | The column index of the cell. |
| `templateOptions?` | [`ICellTemplateOptions`](../interfaces/GC.Spread.Sheets.NamedCellTemplates.ICellTemplateOptions) | - |

#### Returns

`void`

___

### <a id="get" name="get"></a> get

▸ **get**(`name`): ``null`` \| [`INamedCellTemplate`](../interfaces/GC.Spread.Sheets.NamedCellTemplates.INamedCellTemplate)

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

**`example`**
```javascript
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`](../interfaces/GC.Spread.Sheets.NamedCellTemplates.INamedCellTemplate)

The template or null if not found.

___

### <a id="has" name="has"></a> has

▸ **has**(`name`): `boolean`

Check whether a template with the given name exists.

**`example`**
```javascript
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.

___

### <a id="remove" name="remove"></a> remove

▸ **remove**(`name`): ``null`` \| [`INamedCellTemplate`](../interfaces/GC.Spread.Sheets.NamedCellTemplates.INamedCellTemplate)

Remove a template by name.

**`example`**
```javascript
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`](../interfaces/GC.Spread.Sheets.NamedCellTemplates.INamedCellTemplate)

The removed template or null if not found.
