ReferenceAPI
Sheet
A worksheet: ranges, tables, rules, validation, charts and pictures.
A worksheet: ranges, tables, rules, validation, charts and pictures. The same text agents read through help().
One sheet of a workbook. Get cells with sheet.range("A1:C3").
| Option | Type | Description |
|---|---|---|
showGridLines (required) |
boolean |
Hide the cell grid lines. |
tabColor (required) |
string | undefined |
The sheet tab’s color, e.g. “accent2”. |
zoom (required) |
number |
Zoom percent (10–400). |
name (required) |
string |
The sheet’s name, as on its tab. |
refName (required) |
string |
The name as formulas write it (‘Q1 Plan’). |
spills (required) |
readonly { anchor: string; range: string }[] |
Arrays that formulas spilled into neighbouring cells: their anchor and the range filled. |
range() (required) |
method |
A rectangle of cells: “A1:C3”, “B2”, “A:C” or “2:5”. |
usedRange (required) |
Range | undefined |
The smallest range holding every cell with content or a format, or undefined for an empty sheet. |
setColumnWidth() (required) |
method |
Sets column widths in px: sheet.setColumnWidth("A", 160), sheet.setColumnWidth("B:F", 96). |
columnWidth() (required) |
method |
Column width in px (64 by default). |
setRowHeight() (required) |
method |
Sets row heights in px: sheet.setRowHeight(1, 32), sheet.setRowHeight("2:10", 24). |
rowHeight() (required) |
method |
Row height in px (20 by default); rows are 1-based. |
autofitColumns() (required) |
method |
Widens columns to fit what their cells show (an estimate from character counts), within min and max px: sheet.autofitColumns("A:F"). |
freeze() (required) |
method |
Keeps rows above and columns left of the split in view: sheet.freeze(1) or sheet.freeze(1, 1). |
frozenPanes (required) |
{ rows: number; columns: number } |
Frozen rows and columns. |
merge() (required) |
method |
Merges cells: sheet.merge("A1:D1"). |
unmerge() (required) |
method |
Removes the merge that covers this address. |
mergedRanges (required) |
string[] |
Merged ranges. |
clear() (required) |
method |
Empties the sheet to rebuild it: cells, formats, merges, tables, conditional formats, validation, charts, pictures and sparklines go; column widths, row heights and frozen panes stay. |
import() (required) |
method |
Writes a table given as text: CSV or TSV, a Markdown pipe table or an HTML table (format detected). |
whatIf() (required) |
method |
A what-if data table, like Excel’s Data Table command. |
dataTables (required) |
readonly { range: string; rowInput?: string; columnInput?: string }[] |
The what-if data tables on the sheet (whole table ranges and input cells). |
pageSetup() (required) |
method |
How the sheet prints: sheet.pageSetup({ orientation: "landscape", paper: "a4", fitTo: { width: 1 }, printArea: "A1:F40", repeatRows: "1:2", footer: "&CPage &P of &N" }). |
printSetup (required) |
PageSetupInput |
The sheet’s print setup, as pageSetup() takes it. |
protect() (required) |
method |
Protects the sheet: locked cells (all, unless formatted with locked: false) can’t be changed in Excel. |
unprotect() (required) |
method |
Removes the sheet’s protection. |
isProtected (required) |
boolean |
Whether the sheet is protected. |
pivots.… (required) |
collection |
|
sparklines.… (required) |
collection |
|
tables.… (required) |
collection |
|
conditionalFormats.… (required) |
collection |
Conditional formats: add, list (the file’s own too), replace and remove rules. |
validations.… (required) |
collection |
Data validation: add, list (the file’s own too), replace and remove rules. |
fileDrawings (required) |
readonly { name: string; kind: "chart" | "picture"; from: string; to: string }[] |
Charts and pictures that came with the file: they are kept as they were, drawn in previews, and can be removed with removeFileDrawing(name). |
removeFileDrawing() (required) |
method |
Removes a chart or picture that came with the file, by its name. |
charts.… (required) |
collection |
|
images.… (required) |
collection |
|
render() (required) |
method |
Draws part of the sheet as an image, so you can look at it: values as formatted, fills, borders, conditional formats, charts and pictures. |
sheet.autofitColumns
Section titled “sheet.autofitColumns”sheet.autofitColumns(columns?: string, options: { min?: number; max?: number }?): thisWidens columns to fit what their cells show (an estimate from character counts), within min and max px: sheet.autofitColumns("A:F").
sheet.autofitColumns("A:F")sheet.charts.add
Section titled “sheet.charts.add”sheet.charts.add(type: ChartType, options: SheetChartOptions): SheetChartA native chart of cells on this (or another) sheet. The first row names the series and the first column holds the categories: charts.add("column", { data: "A1:C13", at: "E2", title: "Revenue by month" }).
Options: SheetChartOptions.
charts.add("column", { data: "A1:C13", at: "E2", title: "Revenue by month" })sheet.charts.items
Section titled “sheet.charts.items”sheet.charts.items: readonly SheetChart[]The charts on this sheet.
sheet.clear
Section titled “sheet.clear”sheet.clear(): thisEmpties the sheet to rebuild it: cells, formats, merges, tables, conditional formats, validation, charts, pictures and sparklines go; column widths, row heights and frozen panes stay.
sheet.columnWidth
Section titled “sheet.columnWidth”sheet.columnWidth(column: string | number): numberColumn width in px (64 by default).
sheet.conditionalFormats.add
Section titled “sheet.conditionalFormats.add”sheet.conditionalFormats.add(ranges: string | string[], rule: ConditionalRuleInput): WorksheetFormats cells by rule: add("C2:C13", { type: "cellIs", operator: "<", value: 0, format: { color: "red-700" } }), add("D2:D13", { type: "dataBar", color: "accent1" }), add("B2:B13", { type: "colorScale", colors: ["white", "green-400"] }).
Options: ConditionalRuleInput.
add("C2:C13", { type: "cellIs", operator: "<", value: 0, format: { color: "red-700" } })add("D2:D13", { type: "dataBar", color: "accent1" })add("B2:B13", { type: "colorScale", colors: ["white", "green-400"] })sheet.conditionalFormats.clear
Section titled “sheet.conditionalFormats.clear”sheet.conditionalFormats.clear(range?: string): WorksheetRemoves every rule, or those touching a range: clear("C2:C40").
clear("C2:C40")sheet.conditionalFormats.count
Section titled “sheet.conditionalFormats.count”sheet.conditionalFormats.count(): numberHow many conditional format rules the sheet has.
sheet.conditionalFormats.items
Section titled “sheet.conditionalFormats.items”sheet.conditionalFormats.items: readonly { ranges: string[]; rule?: ConditionalRuleInput; fromFile: boolean; kind: string }[]The rules, in order (later ones apply first in Excel), including those read from the file. A file rule Artiwright can’t express has no rule; it is kept and can be removed.
Options: ConditionalRuleInput.
sheet.conditionalFormats.remove
Section titled “sheet.conditionalFormats.remove”sheet.conditionalFormats.remove(index: number): WorksheetRemoves a rule by its position in items.
sheet.conditionalFormats.replace
Section titled “sheet.conditionalFormats.replace”sheet.conditionalFormats.replace(index: number, rule: ConditionalRuleInput, ranges?: string | string[]): WorksheetReplaces a rule (by its position in items) and keeps its ranges unless new ones are given.
Options: ConditionalRuleInput.
sheet.dataTables
Section titled “sheet.dataTables”dataTables: sheet.dataTables: readonly { range: string; rowInput?: string; columnInput?: string }[]The what-if data tables on the sheet (whole table ranges and input cells).
sheet.fileDrawings
Section titled “sheet.fileDrawings”fileDrawings: sheet.fileDrawings: readonly { name: string; kind: "chart" | "picture"; from: string; to: string }[]Charts and pictures that came with the file: they are kept as they were, drawn in previews, and can be removed with removeFileDrawing(name).
sheet.freeze
Section titled “sheet.freeze”sheet.freeze(rows: number, columns?): thisKeeps rows above and columns left of the split in view: sheet.freeze(1) or sheet.freeze(1, 1).
sheet.freeze(1)sheet.freeze(1, 1)sheet.frozenPanes
Section titled “sheet.frozenPanes”frozenPanes: sheet.frozenPanes: { rows: number; columns: number }Frozen rows and columns.
sheet.images.add
Section titled “sheet.images.add”sheet.images.add(options: SheetImageOptions): SheetImageA picture at a cell: images.add({ source: "logo.png", at: "H2", size: { w: 120, h: 40 } }).
Options: SheetImageOptions.
images.add({ source: "logo.png", at: "H2", size: { w: 120, h: 40 } })sheet.images.items
Section titled “sheet.images.items”sheet.images.items: readonly SheetImage[]The pictures on this sheet.
sheet.import
Section titled “sheet.import”sheet.import(text: string, options: ImportOptions?): RangeWrites a table given as text: CSV or TSV, a Markdown pipe table or an HTML table (format detected). Numbers, percentages, currency, dates and true/false become typed values in the format they were written in; a header row is bolded. Returns the range written: sheet.import(csv, { at: "A1", table: "Sales" }). Text starting with “=” stays text unless formulas: true.
sheet.import(csv, { at: "A1", table: "Sales" })sheet.isProtected
Section titled “sheet.isProtected”isProtected: sheet.isProtected: booleanWhether the sheet is protected.
sheet.merge
Section titled “sheet.merge”sheet.merge(address: string): thisMerges cells: sheet.merge("A1:D1").
sheet.merge("A1:D1")sheet.mergedRanges
Section titled “sheet.mergedRanges”mergedRanges: sheet.mergedRanges: string[]Merged ranges.
sheet.name
Section titled “sheet.name”name: sheet.name: stringThe sheet’s name, as on its tab.
sheet.pageSetup
Section titled “sheet.pageSetup”sheet.pageSetup(input: PageSetupInput): thisHow the sheet prints: sheet.pageSetup({ orientation: "landscape", paper: "a4", fitTo: { width: 1 }, printArea: "A1:F40", repeatRows: "1:2", footer: "&CPage &P of &N" }). Options left out stay as they were.
sheet.pageSetup({ orientation: "landscape", paper: "a4", fitTo: { width: 1 }, printArea: "A1:F40", repeatRows: "1:2", footer: "&CPage &P of &N" })sheet.pivots.add
Section titled “sheet.pivots.add”sheet.pivots.add(source: string, options: PivotOptions): PivotInfoA pivot table from a range (“Data!A1:E200”, first row the field names) or a table name: sheet.pivots.add("Data!A1:E200", { at: "H3", rows: ["Region", "Rep"], columns: "Quarter", values: { field: "Sales", function: "sum" }, filters: "Year" }). The result is written into the cells; Excel rebuilds it from the source when it opens the file.
sheet.pivots.add("Data!A1:E200", { at: "H3", rows: ["Region", "Rep"], columns: "Quarter", values: { field: "Sales", function: "sum" }, filters: "Year" })sheet.pivots.get
Section titled “sheet.pivots.get”sheet.pivots.get(name: string): PivotInfo | undefinedA pivot table on this sheet by name.
sheet.pivots.items
Section titled “sheet.pivots.items”sheet.pivots.items: readonly PivotInfo[]The pivot tables made on this sheet.
sheet.pivots.refresh
Section titled “sheet.pivots.refresh”sheet.pivots.refresh(): voidRecomputes the pivot tables from their sources (after the data changed) and rewrites their cells.
sheet.pivots.remove
Section titled “sheet.pivots.remove”sheet.pivots.remove(name: string): voidRemoves a pivot table and empties its cells.
sheet.printSetup
Section titled “sheet.printSetup”printSetup: sheet.printSetup: PageSetupInputThe sheet’s print setup, as pageSetup() takes it.
sheet.protect
Section titled “sheet.protect”sheet.protect(input: ProtectInput?): thisProtects the sheet: locked cells (all, unless formatted with locked: false) can’t be changed in Excel. sheet.protect({ password: "plan", allow: ["sort", "autoFilter"] }).
sheet.protect({ password: "plan", allow: ["sort", "autoFilter"] })sheet.range
Section titled “sheet.range”sheet.range(address: string): RangeA rectangle of cells: “A1:C3”, “B2”, “A:C” or “2:5”.
sheet.refName
Section titled “sheet.refName”refName: sheet.refName: stringThe name as formulas write it (‘Q1 Plan’).
sheet.removeFileDrawing
Section titled “sheet.removeFileDrawing”sheet.removeFileDrawing(name: string): thisRemoves a chart or picture that came with the file, by its name.
sheet.render
Section titled “sheet.render”sheet.render(options: SheetRenderOptions?): Promise<Uint8Array>Draws part of the sheet as an image, so you can look at it: values as formatted, fills, borders, conditional formats, charts and pictures. Default: every used cell, with headers. await sheet.render({ range: "A1:H20" }).
Options: SheetRenderOptions.
await sheet.render({ range: "A1:H20" })sheet.rowHeight
Section titled “sheet.rowHeight”sheet.rowHeight(row: number): numberRow height in px (20 by default); rows are 1-based.
sheet.setColumnWidth
Section titled “sheet.setColumnWidth”sheet.setColumnWidth(columns: string, px: number): thisSets column widths in px: sheet.setColumnWidth("A", 160), sheet.setColumnWidth("B:F", 96).
sheet.setColumnWidth("A", 160)sheet.setColumnWidth("B:F", 96)sheet.setRowHeight
Section titled “sheet.setRowHeight”sheet.setRowHeight(rows: number | string, px: number): thisSets row heights in px: sheet.setRowHeight(1, 32), sheet.setRowHeight("2:10", 24). Rows are 1-based like Excel’s.
sheet.setRowHeight(1, 32)sheet.setRowHeight("2:10", 24)sheet.showGridLines
Section titled “sheet.showGridLines”showGridLines: sheet.showGridLines: booleanHide the cell grid lines.
sheet.sparklines.add
Section titled “sheet.sparklines.add”sheet.sparklines.add(location: string, data: string, options: SparklineOptions?): SparklineGroupInfoSmall charts inside cells, one per row (or column) of data: sheet.sparklines.add("F2:F10", "B2:E10", { type: "line", high: true, low: "red" }). Types: line, column, winLoss. Data can be on another sheet (“Data!B2:E10”).
sheet.sparklines.add("F2:F10", "B2:E10", { type: "line", high: true, low: "red" })sheet.sparklines.clear
Section titled “sheet.sparklines.clear”sheet.sparklines.clear(): voidRemoves every sparkline on the sheet.
sheet.sparklines.items
Section titled “sheet.sparklines.items”sheet.sparklines.items: readonly SparklineGroupInfo[]The sheet’s sparkline groups.
sheet.sparklines.remove
Section titled “sheet.sparklines.remove”sheet.sparklines.remove(location: string): voidRemoves the sparklines in a range of cells: sheet.sparklines.remove("F2:F10").
sheet.sparklines.remove("F2:F10")sheet.spills
Section titled “sheet.spills”spills: sheet.spills: readonly { anchor: string; range: string }[]Arrays that formulas spilled into neighbouring cells: their anchor and the range filled.
sheet.tabColor
Section titled “sheet.tabColor”tabColor: sheet.tabColor: string | undefinedThe sheet tab’s color, e.g. “accent2”.
sheet.tables.add
Section titled “sheet.tables.add”sheet.tables.add(address: string, options: SheetTableOptions?): SheetTableTurns cells into an Excel table: the first row names the columns. Totals add a row below: sheet.tables.add("A1:D13", { name: "Sales", totals: { Revenue: "sum", Region: { label: "Total" } } }).
Options: SheetTableOptions.
sheet.tables.add("A1:D13", { name: "Sales", totals: { Revenue: "sum", Region: { label: "Total" } } })sheet.tables.get
Section titled “sheet.tables.get”sheet.tables.get(name: string): SheetTable | undefinedA table on this sheet by name.
sheet.tables.items
Section titled “sheet.tables.items”sheet.tables.items: readonly SheetTable[]The tables on this sheet.
sheet.tables.remove
Section titled “sheet.tables.remove”sheet.tables.remove(name: string): voidTurns a table back into plain cells (they keep their values and formats).
sheet.tables.resize
Section titled “sheet.tables.resize”sheet.tables.resize(name: string, address: string): SheetTableGrows or shrinks a table to a new range with the same top-left (header) cell, e.g. after adding a row below it: sheet.tables.resize("Sales", "A1:F8"). Formulas that use the table (SUM(Sales[Revenue])) then cover the new rows. New columns are named by their header cells.
sheet.tables.resize("Sales", "A1:F8")SUM(Sales[Revenue])sheet.unmerge
Section titled “sheet.unmerge”sheet.unmerge(address: string): thisRemoves the merge that covers this address.
sheet.unprotect
Section titled “sheet.unprotect”sheet.unprotect(): thisRemoves the sheet’s protection.
sheet.usedRange
Section titled “sheet.usedRange”usedRange: sheet.usedRange: Range | undefinedThe smallest range holding every cell with content or a format, or undefined for an empty sheet.
sheet.validations.add
Section titled “sheet.validations.add”sheet.validations.add(ranges: string | string[], rule: ValidationInput): WorksheetLimits what can be typed in cells: add("E2:E20", { type: "list", values: ["Low", "High"] }), add("B2:B20", { type: "decimal", min: 0, max: 1, error: "Use a rate from 0 to 1." }).
Options: ValidationInput.
add("E2:E20", { type: "list", values: ["Low", "High"] })add("B2:B20", { type: "decimal", min: 0, max: 1, error: "Use a rate from 0 to 1." })sheet.validations.clear
Section titled “sheet.validations.clear”sheet.validations.clear(range?: string): WorksheetRemoves every rule, or those touching a range.
sheet.validations.count
Section titled “sheet.validations.count”sheet.validations.count(): numberHow many validation rules the sheet has.
sheet.validations.items
Section titled “sheet.validations.items”sheet.validations.items: readonly { ranges: string[]; rule?: ValidationInput; fromFile: boolean; kind: string }[]The rules, including those read from the file (a file rule Artiwright can’t express has no rule).
Options: ValidationInput.
sheet.validations.remove
Section titled “sheet.validations.remove”sheet.validations.remove(index: number): WorksheetRemoves a rule by its position in items.
sheet.validations.replace
Section titled “sheet.validations.replace”sheet.validations.replace(index: number, rule: ValidationInput, ranges?: string | string[]): WorksheetReplaces a rule (by its position in items) and keeps its ranges unless new ones are given.
Options: ValidationInput.
sheet.whatIf
Section titled “sheet.whatIf”sheet.whatIf(range: string, options: { rowInput?: string; columnInput?: string }): RangeA what-if data table, like Excel’s Data Table command. range is the whole table: with a column input, values to try run down its first column and formulas across its top row; with a row input, values across the top row and formulas down the first column; with both, the top-left cell is the formula. Results fill the rest and Excel recomputes them: sheet.whatIf("D2:F8", { columnInput: "B1" }).
sheet.whatIf("D2:F8", { columnInput: "B1" })sheet.zoom
Section titled “sheet.zoom”zoom: sheet.zoom: numberZoom percent (10–400).