structure — Claude Code prompt: Excel sheet operations
structure — a prompt for structural Excel operations: insert and delete rows, columns, sheets, protect sheets. Enforces batching discipline — structural changes separate from data writes.
Apache-2.0 ★ 12,746 updated 2026-10-29
.claude/commands/structure.mdWhat structure does
The prompt defines eight operations for modifying workbook structure: insert_rows, delete_rows, insert_cols, delete_cols, add_sheet, delete_sheet, duplicate_sheet, move_sheet, set_sheet_hidden, and protect_sheet. All structural operations shift cell addresses and automatically rewrite formulas.
Critical requirement: structural operations cannot share a batch with content or format writes. The correct sequence is to submit structural changes, call get_workbook_context again, then write data. When creating a new sheet via add_sheet, explicitly set rows and columns if the data exceeds 1000 rows or 20 columns — the default grid rejects writes beyond its edge.
Deleting rows or columns turns formulas referencing deleted cells into #REF! — the prompt advises checking preview warnings before applying.
What it helps with
- insert rows or columns mid-sheet without manually shifting data
- create a new sheet sized to the expected data before importing a large array
- protect a sheet with a password and allow only sorting and filters
- delete or hide a sheet while keeping others visible
- avoid
#REF!errors when deleting rows referenced by formulas
Example prompts for the agent
- Insert three blank rows before row 2 in
sheetId:123, then fill them from an array - Create a new sheet
resultswith 5000 rows and 30 columns, then copy the table fromdatainto it - Protect sheet
summarywith passwordqwerty, disallow edits, but permit row insertion and autofilter
How to install structure
Manually: put the files in place
.claude/commands/structure.mdHow to use
Paste the text at the start of a chat or into project instructions
Questions about structure
How to install structure in Claude Code?
Copy the prompt to .claude/commands/structure.md in the project root.
What does the structure prompt do?
It describes commands for changing Excel workbook structure: inserting and deleting rows, columns, sheets, protecting sheets, and batching rules — structural operations cannot mix with data writes.
Why does structure require separating structural operations and data writes into different batches?
Structural operations shift cell addresses. New addresses only exist after the batch applies, so writing to "new rows" in the same batch will fail — you must apply structural changes, re-read the context, then write data.
Source text
structure.md · Apache-2.0
# Structural changes guide (structure)
## Operation definitions
- `{op:"insert_rows", sheetId, row:2, count:1}` — row is 1-based; new rows are inserted **before** that row.
- `{op:"delete_rows", sheetId, row, count}` — deletes count rows starting at row.
- `{op:"insert_cols", sheetId, column:"C", count}` — new columns are inserted before that column; column uses the column letter.
- `{op:"delete_cols", sheetId, column, count}`
- `{op:"add_sheet", name, rows?, columns?}` — creates a blank worksheet (no sheetId needed). The grid defaults to **1000 rows × 20 columns**; writes beyond the grid are rejected and formula spills truncate at its edge, so pass `rows`/`columns` sized to the expected data (plus a little headroom) when it will hold more — e.g. `{op:"add_sheet", name:"ja", rows:6700}` before copying ~6600 rows into it.
- `{op:"delete_sheet", sheetId}` — deletes a worksheet; the last remaining sheet cannot be deleted. Formulas on other sheets referencing the deleted sheet become #REF! (listed in the preview warnings); for real xlsx files there is an additional fail-closed guard on save (sheets referenced by formulas/charts/defined names refuse deletion).
- `{op:"duplicate_sheet", sheetId, name?}` — copies a whole worksheet (contents and formats); name is auto-generated when omitted. Unavailable in large-file streaming mode; sheets containing pivot tables cannot be duplicated.
- `{op:"set_sheet_hidden", sheetId, hidden:true|false}` — hides/shows a worksheet; at least one sheet must stay visible.
- `{op:"move_sheet", sheetId, position:1}` — moves to the 1-based tab position.
## Sheet protection
`{op:"protect_sheet", sheetId, protected:true|false, password?, allow?}` — **layout-class**, can share a batch with content/format operations (exempt from the batching discipline below). Written into the file on save and enforced in the editor (locked cells refuse edits). `password` is optional plaintext: it is hashed when protecting and required to unprotect a password-protected sheet. `allow` lists what stays permitted while protected (selectLockedCells, selectUnlockedCells, formatCells, formatColumns, formatRows, insertColumns, insertRows, insertHyperlinks, deleteColumns, deleteRows, sort, autoFilter, pivotTables, objects, scenarios); unlisted flags are false except the two select flags.
## Mandatory batching discipline
Structural operations move cell addresses and **cannot appear in the same batch as content/format/sort-layout operations**. The correct rhythm:
1. Submit the structural changes alone first (multiple structural ops may share a batch, applied in order, effective on submit)
2. Call get_workbook_context / read_range again for the shifted layout
3. Then submit the content/format changes
## Formula references
- On row/column insertion/deletion, all A1 references in the workbook's formulas are rewritten automatically for the shift (including absolute $ references and cross-sheet prefixed references).
- Formulas whose reference target is deleted entirely become **#REF!** — the preview warnings list the affected cells precisely. When this happens, ask the user to confirm, or proactively suggest a fix.
- Range references (like SUM(B2:B10)) shrink automatically on partial deletion — you don't need to repair formulas by hand.
## Common mistakes
- ❌ insert_rows followed by writing into the "new rows" in the same batch — rejected by the mixed-batch rule, and the new rows' addresses don't exist before apply.
- ❌ Continuing to write with old addresses right after a structural change applies — re-read the context first.
- ❌ Using delete_rows to clear data — when you only want to clear contents, use clear_range (structure unchanged, formula references unaffected).
© genspark-ai · Apache-2.0 · genspark-ai/genoffice