Sheet Objects
Excel supports 4 different types of "sheets":
- "worksheets": normal sheets
- "chartsheets": full-tab charts
- "macrosheets": legacy (pre-VBA) macros
- "dialogsheets": legacy (pre-VBA) dialog windows
Generic Sheet Object​
Generic sheets are plain JavaScript objects. Each key that does not start with
!
is an A1
-style address whose corresponding value is a cell object.
Worksheet Range​
The !ref
property stores the A1-style range.
Functions that work with sheets should use this property to determine the range. Cells that are assigned outside of the range are not processed.
For example, in the following sparse worksheet, the cell A3
will be ignored
since it is outside of the worksheet range (A1:B2
):
var ws = {
// worksheet range is A1:B2
"!ref": "A1:B2",
// A1 is in the range and will be included
"A1": { t: "s", v: "SheetJS" },
// cell A3 is outside of the range and will be ignored
"A3": { t: "n", v: 5433795 },
};
Utility functions and functions that handle sheets
should test for the presence of the !ref
field. If the !ref
is omitted or is
not a valid range, functions should treat the sheet as empty.
Cell Storage​
By default, the parsers and utility functions generate "sparse-mode" worksheets.
For a given A1-style address, sheet[ref]
is the
corresponding cell object.
Dense Mode​
When the option dense: true
is passed, parsers will generate a "dense-mode"
worksheet where cells are stored in an array of arrays. sheet["!data"][R][C]
returns the cell object at row R
and column C
(zero-indexed values).
When processing small worksheets in older environments, sparse worksheets are more efficient than dense worksheets. In newer browsers, when dealing with very large worksheets, dense sheets use less memory and tend to be more efficient.
Migrating to Dense Mode (click to show)
Sheet Properties​
Each key starts with !
. The properties are accessible as sheet[key]
.
-
sheet['!ref']
: A1-style sheet range string -
sheet['!margins']
: Object representing the page margins. The default values follow Excel's "normal" preset. Excel also has a "wide" and a "narrow" preset but they are stored as raw measurements. The main properties are listed below:
Page margin details (click to show)
Worksheet Object​
In addition to the aforementioned sheet keys, worksheets also add:
-
ws['!cols']
: array of column objects. Each column object encodes properties including level, width and visibility. -
ws['!rows']
: array of row objects. Each row object encodes properties including level, height and visibility. -
ws['!merges']
: array of merge ranges. Each merge object is a range object that represents the covered range. -
ws['!outline']
: configure how outlines should behave. Options default to the default settings in Excel 2019:
key | Excel feature | default |
---|---|---|
above | Disable "Summary rows below detail" | false |
left | Disable "Summary rows to the right of detail" | false |
ws['!protect']
: object of write sheet protection properties. Thepassword
key specifies the password for formats that support password-protected sheets (XLSX/XLSB/XLS). The writer uses the XOR obfuscation method. The following keys control the sheet protection -- set tofalse
to enable a feature when sheet is locked or set totrue
to disable a feature:
Worksheet Protection Details (click to show)
ws['!autofilter']
: AutoFilter object following the schema:
type AutoFilter = {
ref:string; // A-1 based range representing the AutoFilter table range
}
Other Sheet Types​
Chartsheet Object​
Chartsheets are represented as standard sheets. They are distinguished with the
!type
property set to "chart"
.
The underlying data and !ref
refer to the cached data in the chartsheet. The
first row of the chartsheet is the underlying header.
Macrosheet Object​
Macrosheets are represented as standard sheets. They are distinguished with the
!type
property set to "macro"
.
Dialogsheet Object​
Dialogsheets are represented as standard sheets. They are distinguished with the
!type
property set to "dialog"
.