Skip to content

StyleManager

Manages a workbook’s styles array with efficient deduplication.

This class stores complete styles including number format properties. Cell objects can override these formats using their userZ/formulaZ properties.

The cache uses property-based keys (sorted properties + values) rather than JSON.stringify to ensure deterministic hashing regardless of property insertion order.

A separate collection of NamedStyles is exposed via named.

new StyleManager(initialStyles?, initialNamedStyles?): StyleManager;

Create a new StyleManager.

StyleRelaxed[] = []

Optional array of styles to initialize the anonymous pool with. The dedup cache is pre-populated.

Record<string, NamedStyle> = {}

Optional map of named styles keyed by name. Each Record key must match its entry’s ns.name (case-insensitively) and must be unique case-insensitively; mismatches and duplicates are rejected. Keys are normalised to lowercase internally; the original casing is preserved on each NamedStyle.name.

StyleManager

readonly named: NamedStyles;

Named-style CRUD. See NamedStyles.

get length(): number;

Get the number of styles in the array.

number

findOrCreate(style): number;

Find an existing style or create a new one.

This method first checks the cache for an exact match. If found, returns the existing style’s index. If not found, appends the style to the array, updates the cache, and returns the new index.

style.extendsStyle is canonicalized to the casing registered on the named style before the cache lookup, so two references that differ only in case dedupe to the same list entry.

StyleRelaxed

The style object to find or create

number

The index of the style in the styles array

if style.extendsStyle references a named style that does not exist.


get(index): StyleRelaxed | null;

Get a style by its index.

number

Zero-based index into the styles array

StyleRelaxed | null

The style object, or null if the index is out of bounds


toArray(): readonly StyleRelaxed[];

Get a list of all defined styles.

Returns the internal array, typed as readonly to prohibit external code from modifying the array without updating the cache.

readonly StyleRelaxed[]

Readonly array of styles