# Spreadsheets

The 20 tools for spreadsheets. Before an agent first makes one, it reads guide topic sheets.

## create_sheet

Add a spreadsheet to a space: a real Excel-style workbook (formulas, formats, charts, tables) that people edit live. Start it from tabs of rows, or from a file (an .xlsx, .xlsm, .xls, .xlsb, .ods, .csv or .tsv workbook, by public URL or base64) with everything in it. Shape it with the sheet_* tools and check it (check_sheet). Read guide topic "sheets" first.

Parameters:
- `space_id` (string, required)
- `title` (string, required)
- `tabs` (object[]): Tabs in order. Defaults to one empty tab "Sheet1".
- `file` (object): Start from this workbook instead of tabs (up to 25 MB).

## sheet_execute_command

Run ANY spreadsheet engine command by id with JSON params — every ribbon/menu action is a command. Find ids and parameter docs with sheet_list_commands. Examples: {"command":"cell.set","params":{"cell":"B2","input":"=SUM(A1:A9)"}}; {"command":"home.bold","params":{"range":"A1:C1"}}; {"command":"sheet.insert"}; {"command":"data.removeDuplicates","params":{"range":"A1:C20"}}. Most commands act on the current selection when `range` is omitted. Programmatic calls never open dialogs: missing required params give an error. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9"). Everyone with the sheet open sees the change at once.

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `command` (string, required): Command id, e.g. "cell.set", "home.fillColor", "insert.chart"
- `params` (object): Command parameters (see the `params` field of sheet_list_commands); omit or {} for defaults

## sheet_list_commands

List spreadsheet engine commands: id, label, ribbon path, shortcut, a parameter description (`params`) and whether it can run right now. Use it to discover what sheet_execute_command can do (e.g. search "sort", "border", "chart", "sheet"). Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9").

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `search` (string): Case-insensitive substring matched against id, label and ribbon path

## sheet_inspect_workbook

Summary of the active workbook: title, path, dirty flag, sheets (name, used range, cell count, tables, charts, merges, filters, freeze panes), defined names, current selection and active cell, calculation mode and undo/redo history. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9").

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.

## sheet_read_range

Read cell values from a range as rows (2-D array). Numbers/booleans/strings are returned as JSON values, empty cells as null, errors as {"error":"#DIV/0!"}. Without `range`, reads the sheet's used range. formulas:true returns formula text ("=SUM(B2:B4)") for formula cells; formatted:true returns the displayed text ("$1,234.00", "12%"). Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9").

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `formatted` (boolean): Return display text with number formats applied
- `formulas` (boolean): Return formulas instead of computed values for formula cells
- `range` (string): A1-style range, e.g. "A1:D10", "B:B", "Sheet2!A1:C3"
- `sheet` (string): Sheet name (default: the active sheet)

## sheet_write_range

Write a 2-D array of values starting at the top-left cell of `range` (rows of cells). Numbers, booleans, null (clears) and strings are accepted; strings starting with = are formulas ("=SUM(B2:B4)"), other strings are parsed like typed input ("12%", "1/2/2024", "$5"). One undo step. Example: {"range":"A1","values":[["Item","Cost"],["Rent",1200]]}. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9"). Everyone with the sheet open sees the change at once.

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `range` (string, required): Top-left cell or range, e.g. "A1" or "Sheet2!B3"
- `values` (((string | number | boolean | null)[])[], required): Rows of cell values

## sheet_set_cell

Enter one cell exactly as if typed: a number, text, or a formula starting with = ("=AVERAGE(B2:B9)"). Dependent cells recalculate. Returns the command result; use sheet_get_cell to read the computed value. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9"). Everyone with the sheet open sees the change at once.

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `cell` (string, required): Cell, e.g. "B7" or "Sheet2!C3"
- `input` (string | number | boolean, required): Typed input: number, text or =formula

## sheet_get_cell

Details of one cell: computed value and type, formula, display text, raw input, spill range, style, merge, comment and hyperlink. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9").

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `cell` (string, required): Cell, e.g. "B7" or "Sheet2!C3"

## sheet_evaluate_formula

Evaluate a formula against the active sheet WITHOUT changing any cell, e.g. "=SUM(B2:B10)/COUNT(B2:B10)" or "=VLOOKUP(\"x\",A:B,2,FALSE)". `cell` sets the formula's position for relative references and ROW()/COLUMN(). Use English function names and `,` between arguments; a formula that couldn't be entered in a cell is an error saying why. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9").

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `cell` (string): Evaluate as if in this cell (default: active cell)
- `formula` (string, required): Formula text, with or without the leading =

## sheet_format_range

Apply several formats to a range in one call: bold, italic, underline, font name/size, font color, fill color, number format, horizontal alignment, wrap, borders. Colors are "#RRGGBB" (fontColor also "auto", fillColor also "none"). numberFormat is a name (General, Number, Currency, Accounting, Comma, Percentage, Short Date, Long Date, Time, Fraction, Scientific, Text) or a format code ("#,##0.00", "0%", "yyyy-mm-dd"). Each property runs one command; the result lists them. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9"). Everyone with the sheet open sees the change at once.

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `bold` (boolean): Bold on/off
- `borders` (string | object): A border preset name, or {preset, style?, color?}
- `fillColor` (string): Background color "#RRGGBB" or "none"
- `fontColor` (string): Text color "#RRGGBB" or "auto"
- `fontName` (string): Font family, e.g. "Calibri"
- `fontSize` (number): Font size in points
- `horizontalAlign` (string): Horizontal alignment
- `italic` (boolean): Italic on/off
- `numberFormat` (string): Number format name or code
- `range` (string, required): A1-style range, e.g. "A1:D10", "B:B", "Sheet2!A1:C3"
- `underline` (boolean): Single underline on/off
- `wrapText` (boolean): Wrap text on/off

## sheet_insert_chart

Insert a chart from a data range (first row/column used as series names and categories, like Excel). Returns the chart id. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9"). Everyone with the sheet open sees the change at once.

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `at` (string): Top-left anchor cell (default: right of the data)
- `range` (string, required): Source data range including headers, e.g. "A1:C6"
- `subtype` (string): Variant (optional)
- `title` (string): Chart title
- `type` (string, required): Chart type

## sheet_create_table

Format a range as an Excel table (structured references, banded rows, filter buttons). The first row is the header by default. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9"). Everyone with the sheet open sees the change at once.

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `header` (boolean): First row holds headers (default true)
- `name` (string): Table name (default Table1, Table2…)
- `range` (string, required): Range including the header row, e.g. "A1:D20"
- `style` (string): Table style, e.g. "TableStyleMedium2" (default), "TableStyleLight9"

## sheet_sort_range

Sort a range by one or more columns. keys: [{"column":"B","order":"desc"}, …] or just ["B"]. Without `range` the current region around the selection is sorted; header detection follows Excel unless `header` is given. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9"). Everyone with the sheet open sees the change at once.

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `header` (boolean): The first row is a header (kept in place)
- `keys` ((string | object)[], required): Sort levels, most significant first
- `range` (string): A1-style range, e.g. "A1:D10", "B:B", "Sheet2!A1:C3"

## sheet_filter

Filter rows by a column (turns on AutoFilter on the current region, or `range`, when needed). Give `values` (keep rows whose cell text is one of them), `custom` ({op:">", value:"10", op2?, value2?, and?}), `top` ({count, bottom?, percent?}), or clear:true to remove this column's filter. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9"). Everyone with the sheet open sees the change at once.

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `blanks` (boolean): Also keep blank cells
- `clear` (boolean): Clear this column's filter
- `column` (string, required): Column letter, e.g. "C"
- `custom` (object): Custom criteria: {op: "="|"<>"|">"|">="|"<"|"<="|"beginsWith"|"contains"…, value, op2?, value2?, and?: bool}
- `range` (string): Data range to filter (default: the current region of the selection)
- `top` (object): Top/bottom N: {count, bottom?: bool, percent?: bool}
- `values` ((string | number | boolean)[]): Values to keep

## sheet_list_functions

List worksheet functions: name, category, signature and description. Filter with `search` (name or description) or `category`. Acts on the spreadsheet item_id, on the tab named by `tab` (default: the first) unless the range names one ("'Q1 Budget'!B4:D9").

Parameters:
- `item_id` (string, required): The spreadsheet (from create_sheet or get_space)
- `tab` (string): The tab this call works on (default: the first). Commands without a range — charts, pictures, shapes, frozen panes, tab settings — act on this tab.
- `selection` (string): Cells to select on that tab for this call ("B2:D9"; several areas with commas, "A1:A9,C1:C9"). Commands that act on the selection — paste, fill, table and PivotTable commands, sort or filter without a range — act there.
- `category` (string): Category, e.g. "Math & Trig", "Lookup & Reference"
- `search` (string): Substring of the name or description

## sheet_run_commands

Run several spreadsheet engine commands in order in one call (each as sheet_execute_command runs it), e.g. edit.copy then edit.pasteSpecial, or a block of formatting and structure. Nothing anyone else does lands in between. Stops at the first command that fails and says which; the ones before it stay done (sheet_undo takes back the whole run).

Parameters:
- `item_id` (string, required)
- `tab` (string): Default tab for every command (default: the first)
- `commands` (object[], required)

## sheet_undo

Take back your own latest change to the spreadsheet (one tool call, or one sheet_run_commands run); call again for the one before. Only while nobody has changed the sheet since: it never takes back a person's or another agent's work. Everyone with the sheet open sees it go back.

Parameters:
- `item_id` (string, required)

## check_sheet

Check a workbook the way a careful reader would: formula errors (#DIV/0!, #REF!, …) with the formula behind them, numbers stored as text, numbers too wide for their column (####), text cut off by a filled cell beside it (measured with the fonts the sheet is drawn in), long tables without a frozen header, empty tabs. Run it before you hand a sheet over.

Parameters:
- `item_id` (string, required)

## render_sheet

See a tab as people see it in Artifacts: a screenshot of the sheet drawn by the spreadsheet engine (values, formats, column widths, frozen panes, charts, pictures), scrolled so `range` is in view. Look after you change layout, colours or charts; check_sheet finds what a picture hides (formula errors, numbers stored as text).

Parameters:
- `item_id` (string, required)
- `tab` (string): Default: the first tab
- `range` (string): A cell or range to bring into view, e.g. "H4:P24" for a chart there. Default A1.
- `width` (integer): Pixels, default 1400
- `height` (integer): Pixels, default 900

## export_sheet

Links to download the spreadsheet as an Excel workbook (.xlsx) or one tab as CSV. Fetch them with your Artifacts key (Authorization: Bearer).

Parameters:
- `item_id` (string, required)
