set_cells
Writes values or formulas into individual spreadsheet cells while preserving styles and formats. Shows a dry run by default, then saves edits to a new .xlsx file.
Instructions
Write single cells, changing nothing else. DRY RUN BY DEFAULT: shows before/after for every cell and writes nothing; repeat with dry_run=false to save.
changes: list of {"cell": "B7", "value": ...} or {"cell": "B7", "formula": "SUM(B2:B6)"}, with an optional per-change "sheet". Value coercion rules:
a string starting with '=' is a FORMULA ("=SUM(A1:A3)")
a string starting with a single quote is literal TEXT with the quote removed ("'=not a formula" stores =not a formula; "'007" stores the text 007)
JSON numbers are numbers, true/false are booleans, null clears the cell
ISO strings 'YYYY-MM-DD' and 'YYYY-MM-DDTHH:MM[:SS]' become real dates (the cell keeps its date format, or gets yyyy-mm-dd); use a leading quote to keep such a string as text
any other string is text (never auto-converted to a number) Existing styles, number formats, validations, conditional formats and column widths are kept. Writes into merged-cell interiors and array formulas are refused. Formulas referring to a sheet that does not exist are refused.
The result goes to a NEW file '.edited.xlsx' next to the original unless output= is given; an existing file is never replaced unless overwrite=true (use overwrite=true with output equal to path to edit in place). If the workbook has features openpyxl would drop (see workbook_overview) the edit is refused unless allow_loss=true. All formulas lose their cached results on save (Excel recalculates when opened).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| sheet | Yes | ||
| output | No | ||
| changes | Yes | ||
| dry_run | No | ||
| overwrite | No | ||
| allow_loss | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |