Wraps an existing sheet data object. Typically obtained via
Workbook.getSheet() or Workbook.addSheet().
The underlying sheet data model.
Optionalstyles: StylesData
Optional shared styles from the parent workbook.
OptionalworkbookData: WorkbookData
Optional parent workbook data for cross-sheet operations.
Optionalworkbook: Workbook
Internal: the owning workbook, which passes itself so the
name setter renames through Workbook.renameSheet.
Returns the auto-filter configuration, or null if none is set.
Sets the auto-filter. Accepts an AutoFilterData object, a range string (e.g., "A1:D10"), or null to clear.
Returns all charts on this sheet.
Returns the column definitions (width, visibility) for this sheet.
Returns all cell comments in this sheet.
Returns the worksheet dimension string from the source file, or null if not set.
Returns the frozen pane split position, or null if no panes are frozen.
Freezes rows and/or columns at the given split position, or clears the freeze
with null. Setting a frozen pane clears any split pane and the per-pane selections.
Returns the header/footer configuration, or null if unset.
Returns all hyperlinks defined in this sheet.
Returns all merged cell ranges (e.g., "A1:C3").
Returns the sheet tab name.
Renames the sheet tab, validated against Excel's sheet-name rules: 1-31
UTF-16 code units, none of \ / * ? [ ] : and no control character
(Unicode Cc), no leading or trailing apostrophe, and not History in any case.
On a sheet that belongs to a workbook this is Workbook.renameSheet: the name must be unique ignoring case and canonical equivalence, and defined names that refer to the sheet are rewritten. A standalone worksheet only validates the name.
ModernXlsxError with code INVALID_ARGUMENT if the name is empty,
exceeds 31 UTF-16 code units, contains forbidden characters, starts or ends
with an apostrophe, is the reserved name History (any case), or is already used by another sheet of the
workbook (any case or normal form); nothing is changed then.
Returns the outline (grouping) properties, or null if unset.
Sets or clears the outline properties (summaryBelow, summaryRight).
Returns the page breaks configuration, or null if unset.
Returns the page margins (top, bottom, left, right, header, footer), or null if unset.
Sets or clears the page margins. Creates a page setup object if needed.
Returns the page setup configuration (orientation, paper size, etc.), or null if unset.
Returns per-pane selection state, or empty array.
Returns all pivot tables on this sheet.
Returns the number of populated rows in the sheet.
Returns all rows in the sheet, sorted by 1-based row index.
Returns the sheet protection settings, or null if the sheet is unprotected.
Sets or clears sheet protection. Pass null to remove protection. Each flag is
written as given: true locks the action in Excel, false allows it (see
SheetProtectionData); set plainPassword to require a password.
Returns all slicers on this sheet.
Returns all sparkline groups on this sheet.
Returns the split pane configuration, or null if no split pane is active.
Sets a split pane. Setting a split pane clears any frozen pane. Pass null to
clear it, which also clears the per-pane selections.
Returns the sheet visibility state.
Returns the sheet tab colour hex string: the ARGB value stored in the file
(e.g. "FFFF0000") on a workbook read from a file, or the string last set;
null when no tab colour is set or it has no RGB value (a theme or indexed
colour).
Sets the sheet tab colour as hex RGB (RRGGBB) or ARGB (AARRGGBB), with
or without a leading #; written as uppercase ARGB. Pass null to clear.
Returns all table definitions on this sheet.
Returns all threaded comments in this sheet.
Returns all timelines on this sheet.
Returns the computed used range (e.g., "B2:D5") or null if the sheet has no cells.
Returns all data validation rules applied to this sheet.
Returns the sheet view configuration, or null if using defaults.
Sets sheet view configuration. Pass null to reset to defaults.
Returns the view mode: 'normal', 'pageBreakPreview', or 'pageLayout'.
Adds a chart to this worksheet using a builder callback.
The chart type (e.g., 'bar', 'line', 'pie', 'scatter').
A callback that receives a ChartBuilder for fluent configuration.
Adds a pre-built chart definition to this worksheet.
The complete chart data object (produced by ChartBuilder.build()).
Adds a manual column page break with id set to col and max 1048575. ECMA-376
places a column break left of the zero-based column id, so the break falls to the
right of the 1-based column col.
The break id: the 1-based number of the last column left of the break.
Adds a hyperlink to a cell. A value that starts with a URI scheme
(/^[A-Za-z][A-Za-z0-9+.-]*:/: https:, mailto:, file:, and also a drive
path such as C:\book.xlsx) is stored as the external target, written as a
sheet relationship with TargetMode="External"; anything else, including a
same-sheet range such as 'A1:B2' or 'B:D', is an in-workbook location
such as 'Sheet2!A1' or a defined name.
The cell reference to attach the hyperlink to (e.g., 'A1').
External URL, mailto: address or file, or an in-workbook
reference (e.g., 'https://example.com' or 'Sheet2!A1').
Optionalopts: { display?: string; tooltip?: string }
Optional display text and tooltip.
Adds a pivot table definition to this sheet. Its cacheId must name a pivot cache of
the workbook, such as one added with Workbook.addPivotCache (the write fails
otherwise). A row, column or page field with empty items is completed from that cache
on write, and the cache then refreshes when Excel opens the file (see PivotTableData).
The pivot table data to add.
Adds a pivot table using a fluent builder callback.
Adds a manual row page break with id set to row and max 16383. ECMA-376
places a row break above the zero-based row id, so the break falls below the
1-based row row.
The break id: the 1-based number of the last row above the break.
Adds a slicer to this sheet.
The slicer definition to add.
Adds a sparkline group to this sheet.
The sparkline group definition.
Adds a table definition to the sheet.
The displayName must be a name Excel opens: 1 to 255 UTF-16 code units;
no space, tab, line break, DEL or ASCII punctuation other than _, .,
\ and ?; not starting with a digit, ., ? or a combining mark
(Unicode M; Excel refused U+0301 + abc and U+093F + x, while
a + U+0301 + bc opens; a leading Thai mark such as U+0E34 + a,
which Excel opens, is refused too); not TRUE or FALSE;
not a cell reference in the grid (T2, xfd1; XFE1 and A0 are fine);
and not an R1C1 reference or a name that starts with one (R, C, RC,
R1x, C1_, RC2x; a . right after the number, as in R1.a, is fine).
Case is ignored. It must also differ, ignoring case and canonical
equivalence, from the display name of every other table and from every
defined name in the workbook. An explicit name may be at most 255 code
units and must differ, compared the same way, from every other table's
explicit name.
With totalsRowCount 1, Excel keeps a table's totals as ordinary cells in
the last row of its range, so this method also writes them: for each column
with a totalsRowFunction ('sum', 'average', 'count', 'countNums',
'max', 'min', 'stdDev' or 'var') the SUBTOTAL formula Excel writes
(SUBTOTAL(109,Table1[Amount]) for 'sum'), for 'custom' the column's
totalsRowFormula, and for a column with a totalsRowLabel and no function
the label text. The formulas have no cached value, so Excel computes them
when it opens the file. A table read from a file is not changed.
A totals cell that already holds a value or a formula is kept as it is, and Excel opens the file only if the kept cell agrees with its column (Excel 365 probes):
SUBTOTAL column: a plain value (number, text, boolean), or the
formula above, which Excel also takes without the table name
(SUBTOTAL(109,[Amount])) and with the function or column name in
another case; any other formula is refused, the table name in another
case and a space inside the parentheses included;'custom' column with a totalsRowFormula: any formula; a value or an
empty cell is refused (without a totalsRowFormula, anything opens);totalsRowLabel and no function (or 'none'): the label
text, exactly, or nothing; other text, a number, a boolean or a formula
is refused;Workbook.validate() reports a totals cell Excel refuses as an error.
A column's calculatedColumnFormula and totalsRowFormula are stored in
the form Excel writes in a file, which has no @ this-row shorthand:
Excel refuses to open a table definition holding [@Qty],
[@[Unit Cost]], Table1[@Qty] or [@] (outside a string literal);
write Table1[[#This Row],[Qty]], Table1[[#This Row],[Unit Cost]] or
Table1[#This Row] there. [Qty] and [[#This Row],[Qty]] without the
table name open. A [@...] that names a column of its table, ignoring
case, is a whole-column reference and opens: Excel writes the column
@Home of table AtT as AtT[@Home] (the names compared after their
_xHHHH_ escapes are decoded). A [@...] of a table in another
workbook, which Excel stores as [1]!Ext[@Home], is not checked. The
formulas are kept as given.
The table definition to add (range, columns, style, etc.).
ModernXlsxError with code INVALID_ARGUMENT if the display name or
the name breaks one of the rules above (duplicates are found ignoring
case and canonical equivalence: café with U+00E9 repeats cafe +
U+0301), or a calculatedColumnFormula
or totalsRowFormula uses the @ shorthand (the message gives the form
to write instead); the sheet is unchanged then.
Adds a threaded comment to the given cell reference: the root of a new thread. A cell holds one thread (Excel shows only the first thread on a cell and drops the rest), so a cell that already has a thread root throws; add to that thread with Worksheet.replyToComment instead. Creates a person entry in the workbook if the author does not exist yet.
The comment and person ids are upper-case GUIDs in braces
({XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}), the form Excel requires. On
write the sheet also gets the legacy placeholder note Excel needs to show
the thread (author tc={id}, text [Threaded comment] ... Comment:
and the replies), with its hidden note shape. It is added to the file
only, not to Worksheet.comments, and only when the cell has no
note: a note already on the cell is written as it is, and Excel then
shows that note, not the thread. A read of the file returns the
placeholder in Worksheet.comments, as it does for a file Excel
saved, and later writes keep it as it is.
The comment's timestamp is the current time as an ISO 8601 UTC string
(new Date().toISOString() form). The writer writes it as dT in the
form Excel reads (UTC, hundredths of a second, no Z); a read returns
dT as the file holds it.
The cell reference (e.g., 'A1'); it is stored without $
and in upper case ('$d$4' becomes 'D4'), and cells are compared that
way ('a1', '$A$1' and 'A1' are one cell).
The comment text: at most 32,767 UTF-16 code units (its
length; an astral character such as an emoji counts as two). Excel
refuses a file with a longer threaded comment.
The display name of the author.
The ID of the created comment, an upper-case GUID in braces.
ModernXlsxError with code INVALID_ARGUMENT, leaving the worksheet
unchanged, if the cell already has a thread root (the message names the
cell and the root's ID to pass to replyToComment), if text is longer
than 32,767 UTF-16 code units, or on a worksheet that was not obtained
from a workbook.
Adds a timeline to this sheet.
The timeline definition to add.
Adds a data validation rule to the given cell range reference.
The cell range to validate (e.g., 'B2:B100').
The validation rule: validationType, operator, formula1,
formula2, allowBlank, showErrorMessage, errorTitle and
errorMessage (each null when unused), plus the optional
showInputMessage, promptTitle and prompt.
Returns the cell at the given A1-style reference, creating the row and cell if needed.
The returned Cell is a live wrapper -- mutations are reflected in the underlying sheet data.
A1-style cell reference (e.g., 'B3', 'AA100').
A mutable Cell wrapper.
Removes all sparkline groups from this sheet.
Collapses grouped rows: hides each row in the range that has an outline level
and marks the summary row collapsed. The summary row is the row after the
range, or the row before it when outlineProperties.summaryBelow is false.
1-based start row index (inclusive).
1-based end row index (inclusive).
Expands collapsed grouped rows: shows each row in the range that has an outline
level and clears collapsed on the summary row (see Worksheet.collapseRows).
1-based start row index (inclusive).
1-based end row index (inclusive).
Gets the print area for this sheet.
The defined name value (e.g., "Sheet1!$A$1:$D$50") or null.
Returns the table with the given display name, or undefined if not found.
The table display name to look up.
The matching TableDefinitionData, or undefined.
Groups columns by setting their outline level (1-7), creating missing column definitions.
1-based start column index (inclusive).
1-based end column index (inclusive).
Outline level, clamped to 0-7; 0 clears the level. Defaults to 1.
Groups rows by setting their outline level (1-7), creating missing rows.
1-based start row index (inclusive).
1-based end row index (inclusive).
Outline level, clamped to 0-7; 0 clears the level. Defaults to 1.
Removes a chart by index.
Zero-based index of the chart to remove.
true if removed, false if index is not an in-range integer.
Removes the comment on the given cell reference.
The cell reference whose comment should be removed.
true if the comment was removed, false if not found.
Removes the hyperlink on the given cell reference.
The cell reference to remove the hyperlink from (e.g., 'A1').
true if the hyperlink was removed, false if not found.
Removes a merged cell range.
The A1-style range to un-merge (e.g., 'A1:C3').
true if the range was removed, false if not found.
Removes a pivot table by index.
Zero-based index of the pivot table to remove.
true if the pivot table was removed, false if index is not an
in-range integer.
Removes a slicer by index.
Zero-based index of the slicer to remove.
true if the slicer was removed, false if index is not an
in-range integer.
Removes the table with the given display name.
The table display name to remove.
true if the table was removed, false if not found.
Removes a timeline by index.
Zero-based index of the timeline to remove.
true if the timeline was removed, false if index is not an
in-range integer.
Removes the data validation rule for the given cell range reference.
The cell range whose validation rule should be removed.
true if the rule was removed, false if not found.
Replies to an existing threaded comment. Creates a person entry in the workbook if the author does not exist yet.
The reply's parentId is the thread root: a reply to a reply joins its
thread root, as Excel does (Excel refuses a file whose reply names
another reply as its parent).
Excel shows a thread's replies in the order of their timestamps (dT,
which it keeps to the hundredth of a second). The reply's timestamp
is the current time as an ISO 8601 UTC string, or, when that is not at
least 10 ms after the latest timestamp already in the thread (replies
added within the same hundredth, or a thread stamped ahead of this
clock), that latest timestamp plus 10 ms, so replies show in the order
they were added. A timestamp without a zone, as Excel writes dT, is UTC.
The ID of the comment to reply to (a thread root or a reply), exactly as Worksheet.addThreadedComment or Worksheet.replyToComment returned it or the file holds it.
The reply text: at most 32,767 UTF-16 code units (its
length; an astral character such as an emoji counts as two). Excel
refuses a file with a longer threaded comment.
The display name of the reply author.
The ID of the reply comment, an upper-case GUID in braces.
Sets the width of a single 1-based column, creating or updating its definition.
The 1-based column index.
The column width in Excel character units.
Sets the print area for this sheet via a _xlnm.Print_Area defined name.
Does nothing on a worksheet that does not belong to a workbook.
Excel refuses a file whose print area has no sheet qualifier, so every
comma-separated area of ref that lacks one ("A1:B2") is stored qualified
with this sheet's name, quoted when needed ("'My Sheet'!A1:B2"), and
otherwise as written; a qualified area ("Sheet1!$A$1:$D$50") is stored as it is.
The reference or comma-separated list of references (cell, range,
column span or row span). Pass null to clear.
Sets the height (in points) of the given 1-based row, creating it if needed.
The height is written as a custom height (customHeight="1"), so Excel
shows it instead of sizing the row to its content.
The 1-based row index.
Row height in points (e.g., 24 for double-height).
Ungroups columns by clearing their outline level.
1-based start column index (inclusive).
1-based end column index (inclusive).
Ungroups rows by clearing their outline level.
1-based start row index (inclusive).
1-based end row index (inclusive).
Represents a single worksheet within a workbook.
Provides access to cells, rows, columns, merge ranges, charts, pivot tables, comments, hyperlinks, page setup, and other sheet-level features.
Example