editCells
Permanently write values or formulas to cells. Merge or unmerge cells.
IMPORTANT: After editing, you MUST call readCalculatedValues to see the resulting changes. The tool returns a delta showing changes, but you should verify formulas propagated correctly.
Writing text over a cell that held a number or date is reported in warnings (level “high” or “low”). A “high” warning usually means a real value was turned into a text string that only looks the same — write the value itself, not its displayed text.
Examples:
- Set value: { “apply”: [{ “target”: “A1”, “value”: 100 }], “note”: “Set initial value” }
- Set formula: { “apply”: [{ “target”: “B1”, “value”: “=A1*2” }], “note”: “Add formula” }
- With style: { “apply”: [{ “target”: “A1”, “value”: 100, “styleIndex”: 0 }], “styles”: [{ “bold”: true }], “note”: “Bold value” }
- Merge cells: { “apply”: [], “merge”: [“A1:B2”], “note”: “Merge header” }
- Unmerge: { “apply”: [], “unmerge”: [“A1:B2”], “note”: “Unmerge cells” }
Formulas must start with ”=”. Values are auto-detected as number, boolean, or string.
| Parameter | Type | Description | |
|---|---|---|---|
apply | object[] | required | Array of cell edits to apply |
apply[].target | string | required | Cell reference (e.g., “A1”, “Sheet1!B2”) |
apply[].value | string | number | boolean | null | optional | Value or formula to write. Formulas start with ”=”. Omit to only apply style. |
apply[].styleIndex | number | optional | Index into the styles array to apply |
styles | object[] | optional | Array of style objects referenced by styleIndex in apply items |
styles[].bold | boolean | optional | Bold text |
styles[].borderBottomColor | string | optional | Bottom border color |
styles[].borderBottomStyle | "none" | "dashDot" | "dashDotDot" | "dashed" | "dotted" | "double" | "hair" | "medium" | "mediumDashDot" | "mediumDashDotDot" | "mediumDashed" | "slantDashDot" | "thick" | "thin" | optional | Bottom border style |
styles[].borderLeftColor | string | optional | Left border color |
styles[].borderLeftStyle | "none" | "dashDot" | "dashDotDot" | "dashed" | "dotted" | "double" | "hair" | "medium" | "mediumDashDot" | "mediumDashDotDot" | "mediumDashed" | "slantDashDot" | "thick" | "thin" | optional | Left border style |
styles[].borderRightColor | string | optional | Right border color |
styles[].borderRightStyle | "none" | "dashDot" | "dashDotDot" | "dashed" | "dotted" | "double" | "hair" | "medium" | "mediumDashDot" | "mediumDashDotDot" | "mediumDashed" | "slantDashDot" | "thick" | "thin" | optional | Right border style |
styles[].borderTopColor | string | optional | Top border color |
styles[].borderTopStyle | "none" | "dashDot" | "dashDotDot" | "dashed" | "dotted" | "double" | "hair" | "medium" | "mediumDashDot" | "mediumDashDotDot" | "mediumDashed" | "slantDashDot" | "thick" | "thin" | optional | Top border style |
styles[].fillColor | string | optional | Cell background color as hex code |
styles[].… | + 11 more properties | ||
note | string | required | Description of this edit for version history |
merge | string[] | optional | Array of ranges to merge (e.g., [“A1:B2”, “D4:E6”]). Each range must span at least 2 cells. |
unmerge | string[] | optional | Array of ranges to unmerge. Can specify exact merged range or any cell within a merge. |