[]
Sheets.NamedCellTemplates.NamedCellTemplatesManager
• new NamedCellTemplatesManager()
Represents a manager for named cell templates. Stores and retrieves cell configuration templates that can be applied to cells.
▸ 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);
| Name | Type | Description |
|---|---|---|
name |
string |
The unique name for this template. |
template |
INamedCellTemplate |
The template definition. |
void
▸ all(): INamedCellTemplate[]
Get all templates.
example
var templates = workbook.namedCellTemplates.all();
templates.forEach(function(template) {
console.log(template.name);
});
Array of all templates (copies).
▸ clear(): void
Clear all templates.
example
workbook.namedCellTemplates.clear();
void
▸ 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 });
| 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 |
- |
void
▸ 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);
}
| Name | Type | Description |
|---|---|---|
name |
string |
The name of the template to retrieve. |
null | INamedCellTemplate
The template or null if not found.
▸ has(name): boolean
Check whether a template with the given name exists.
example
if (workbook.namedCellTemplates.has('myTemplate')) {
console.log('Template exists');
}
| Name | Type | Description |
|---|---|---|
name |
string |
The name of the template to check. |
boolean
True if the template exists, false otherwise.
▸ remove(name): null | INamedCellTemplate
Remove a template by name.
example
var removedTemplate = workbook.namedCellTemplates.remove('myTemplate');
if (removedTemplate) {
console.log('Template removed:', removedTemplate.name);
}
| Name | Type | Description |
|---|---|---|
name |
string |
The name of the template to remove. |
null | INamedCellTemplate
The removed template or null if not found.