Formula Overwrite Guard

Previews which cells a spreadsheet paste would change, so formulas, locked cells and headings aren't wiped silently.

StopsPaste wiped spreadsheet formulas

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/formula-overwrite-guard.json

The files land in your project. They're yours to edit.

Usage

formula-overwrite-guard-usage.tsx
import { FormulaOverwriteGuard, type Grid } from "@/components/ui/formula-overwrite-guard"

return <FormulaOverwriteGuard value={sheet} onValueChange={(g) => setSheet(recalc(g))} defaultPaste={{ text: COPIED, row: 2, col: 1 }} />

What it catches

  • Pastes that overwrite formulas
  • Locked cells and the heading row
  • Data spilling past the table edge
  • A heading row copied along with the data

Props

FormulaOverwriteGuard props
PropTypeDefault
value

Controlled cells, row by row.

Grid—
defaultValue

Initial cells when uncontrolled.

Grid[]
onValueChange

Called with the new cells after a paste or undo.

(grid: Grid) => void—
headerRows

How many top rows are headings.

number1
defaultPaste

Opens with this paste under review (for restoring an unresolved paste, and for demos).

{ text: string; row: number; col: number }—
messages

Any visible string.

Partial<Omit<FormulaGuardMessages, "legend">> & { legend?: Partial<Record<CellFate, string>> }—

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • The preview is a role="region" with an aria-label summarising rows, columns and cell
  • Locked and formula cells use icons plus text
  • Actions are buttons with visible text

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Works on the grid model you pass; it isn't connected to a spreadsheet engine
  • "Safe" paste skips cells rather than merging values

What it stops

Paste wiped spreadsheet formulas

Also known as

spreadsheet · data grid · paste · excel · google sheets · formulas · paste special · ag grid

Field type

Dependencies

Pairs well with