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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new StyleManager(
initialStyles):StyleManager
Creates a new StyleManager.
Parameters
Section titled “Parameters”initialStyles
Section titled “initialStyles”StyleRelaxed[] = []
Optional array of styles to initialize with. The cache will be pre-populated for these styles.
Returns
Section titled “Returns”StyleManager
Accessors
Section titled “Accessors”length
Section titled “length”Get Signature
Section titled “Get Signature”get length():
number
Get the number of styles in the array.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”findOrCreate()
Section titled “findOrCreate()”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.
Parameters
Section titled “Parameters”StyleRelaxed
The style object to find or create
Returns
Section titled “Returns”number
The index of the style in the styles array
get(
index):null|StyleRelaxed
Get a style by its index.
Parameters
Section titled “Parameters”number
Zero-based index into the styles array
Returns
Section titled “Returns”null | StyleRelaxed
The style object, or null if the index is out of bounds
toArray()
Section titled “toArray()”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.
Returns
Section titled “Returns”readonly StyleRelaxed[]
Readonly array of styles