CSV Export Guard

CSV Export Guard is a copy-paste React component that stops excel ate the leading zeros before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/csv-export-guard
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsExcel ate the leading zeros

Was this component page useful?

How do I install CSV Export Guard?

pnpm dlx shadcn@latest add @bollard/csv-export-guard

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

How do I use CSV Export Guard in React?

csv-export-guard-usage.tsx
import { CsvExportGuard } from "@/components/ui/csv-export-guard"

<CsvExportGuard rows={ROWS} columns={COLUMNS} filename="orders.csv" onExport={(csv) => setLast(csv.split("\r\n")[2])} />

What input mistakes does CSV Export Guard catch?

  • Leading zeros and + signs dropped from phone numbers and codes
  • Long numeric IDs turned into scientific notation
  • Values like "3-4" turned into dates
  • Cells starting with = + - @ that run as formulas (CSV injection)

What props does CSV Export Guard accept?

CsvExportGuard props
PropTypeDefault
rows* (required)

Rows to export.

Record<string, unknown>[]—
columns

Columns in order. Defaults to the keys of the first row.

{ key: string; label: string }[]—
filename

File name for the default download.

string"export.csv"
onExport

Receives the finished CSV. Defaults to downloading it as `filename`.

(csv: string, filename: string) => void—
defaultFixed

Columns fixed from the start.

string[][]
formulaPrefix

Character put in front of formula-looking cells. OWASP suggests a tab for Excel; `'` is the common choice.

string"'"
bom

Prepend a UTF-8 byte-order mark so Excel reads accents and ₹ correctly.

booleantrue
messages

Short phrase per issue kind: "{count} values {phrase}".

Partial<Record<CsvIssueKind, string>>—
title

Heading above the column list.

string"Before you export"
fixLabel

Text for a column's fix toggle.

string"Keep as typed"
fixedLabel

Text for a column's fix toggle when on.

string"Kept as typed"
fixAllLabel

Text for the fix-all button.

string"Fix all"
exportLabel

Export button text.

string"Export CSV"
exportAnywayLabel

`{count}` is filled in.

string"Export with {count} unfixed"
sizeText

Size line under the title.

(columns: number, rows: string) => string(columns, rows) => `${columns} column${columns === 1 ? ""…
valuesText

"{count} values {phrase}" for each issue.

(count: number, phrase: string) => string(count, phrase) => `${count} ${count === 1 ? "value" : "v…
unfixedText

Screen-reader summary while columns would still be changed.

(count: number) => string(count) => `${count} column${count === 1 ? "" : "s"} woul…
allSafeText

Screen-reader summary once every column is safe.

string"Every column opens as typed."
asTextLabel

Shown after a neutralised formula sample.

string"(as text)"
columnsLabel

Accessible name of the column list.

string"Columns"
noProblemsLabel

Accessible name of the check on a clean column.

string"No problems"
opensAsLabel

Read before the "after" sample, e.g. "007 opens as 7".

string"opens as"

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

How is CSV Export Guard accessible?

  • Columns are a labelled list; fix toggles use aria-pressed
  • The "no problems" icon has an aria-label; arrows are aria-hidden
  • Summary is aria-live="polite"

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

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Neutralise formula-leading cells when generating CSV on the server as well, since exports can be produced without this component.

  • Predicts typical Excel/Sheets behaviour; locale settings and other apps may differ
  • Forcing text or prefixing formulas changes the raw CSV, which other importers may not expect
  • Checks the rows you pass, not a whole export streamed from the server

What expensive mistakes does CSV Export Guard stop?

Excel ate the leading zeros

Also known as

csv export · excel · leading zeros · csv injection · pin code · +91 · google sheets · download csv

What dependencies does CSV Export Guard require?

CSV Export Guard facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameCSV Export Guard
Registry identifier@bollard/csv-export-guard
Install commandnpx shadcn@latest add @bollard/csv-export-guard
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about CSV Export Guard

How does CSV Export Guard validate Indian financial identifiers?

CSV Export Guard stops excel ate the leading zeros. Complies with national standards for Leading zeros and + signs dropped from phone numbers and codes, Long numeric IDs turned into scientific notation, Values like "3-4" turned into dates, Cells starting with = + - @ that run as formulas (CSV injection). Limitation: verify csv-export-guard with issuer gateway.

How do I install csv-export-guard with shadcn?

Run `npx shadcn@latest add @bollard/csv-export-guard`. Sources added: registry/default/csv-export-guard/csv-checks.ts, registry/default/csv-export-guard/csv-export-guard.tsx. Package requirements: lucide-react.

What props customize CSV Export Guard?

CSV Export Guard accepts `rows`, `columns`, `filename`, `onExport`, `defaultFixed`. Configures csv export, excel, leading zeros behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of csv-export-guard?

Predicts typical Excel/Sheets behaviour; locale settings and other apps may differ. Forcing text or prefixing formulas changes the raw CSV, which other importers may not expect. Checks the rows you pass, not a whole export streamed from the server Server requirement: Neutralise formula-leading cells when generating CSV on the server as well, since exports can be produced without this component.

How does CSV Export Guard meet accessibility guidelines?

Columns are a labelled list; fix toggles use aria-pressed. The "no problems" icon has an aria-label; arrows are aria-hidden. Summary is aria-live="polite". Minimizes errors: excel removes leading zeros, phone number lost +91.

Which components pair with CSV Export Guard?