Data Operations
X21 exposes a suite of tools for reading and writing worksheet data with precision. Each tool corresponds to a handler inside the Excel API service and is orchestrated by the Deno backend.Reading Data
read_values– Retrieves cell values (and formulas) for a specific range. Responses include:values– 2D array mirroring the requested range.formulas– Optional formula text when available.address– Range address for auditing.
read_format– Gathers formatting attributes (font, colour, alignment, number formats, borders). Powered byFormatManagerand per-attribute readers such asBoldFormatReader.- Usage Tips
- Provide explicit
workbookName,worksheet, andrangeto avoid ambiguity. - Use wildcards like entire columns (
A:A) or rows (3:3) when reading large sections—ExcelSelection can handle them efficiently.
- Provide explicit
Writing Data
write_values– Writes tabular data using a 2D array. Key behaviours:- Dimensions must match the target range; the tool validates before writing.
- Supports formulas (e.g.,
=SUM(A2:A10)). Use relative references for patterns, absolute references for constants. - Returns
oldValuesandnewValuesso changes can be inspected or reverted.
write_format– Applies styling across a range. Payloads can include:- Font properties (
bold,italic,fontSize,fontName). - Colours (hex strings or RGB).
- Borders, alignment, number formats.
- The backend optimises changes using
FormatWriterto reduce redundant operations.
- Font properties (
Best Practices
- Batch large updates into a single tool call to reduce Excel automation overhead.
- For append operations, combine
read_valuesto find the next empty row withwrite_valuesto insert data. - When altering formats, explicitly include only the properties you want to change; the formatter leaves unspecified attributes untouched.
- Use View mode to preview writes before approving. Revert data is generated automatically, enabling quick rollbacks if the outcome isn’t correct.
Error Handling
- Invalid ranges or protected sheets trigger detailed error messages from the Excel API. The tool reports them back to the UI as
tool:error. - If the workbook changes while a tool is pending (e.g., the user edits cells manually), re-run
read_valuesto ensure the latest context before approving writes.

