Skip to content
Calm motion: animations on this site only fade, with no movement

CSV import ​

Read a CSV file, match its columns to your fields, and check the rows

Brings records into an ERP or an admin panel from a spreadsheet. CSV (comma-separated values) is a text file with one record on each line. The file stays in the browser. Your app gets the rows and saves them.

Basic
  • fields is the list of your fields. Each field has a key, a label, and an optional required.
  • The first line of the file is the header. Each field gets the column with the same name, without case, spaces, or marks. A menu for each field changes the match, or skips the field.
  • The preview shows the first rows as your fields (default 5, set by preview). An empty required cell has a dashed red edge.
  • If a required field has no column, an error names it, and the import is off. A row that misses a required value is skipped, and a line says how many.
  • "Import" emits import with the good rows, as objects with your keys. The values are text.
  • loadText(csv) loads CSV text, for example from a paste. Call it through a template ref.
  • The parser follows RFC 4180. It reads quoted fields with commas, line breaks, and "" for a quote. The parseCsv function is exported.
  • Change the words with labels or a label pack: file, match, skip, required, previewTitle, empty, and the functions rows, missing, unmatched, and import.

Usage ​

ts
import { BlessCsvImport } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
fields*BlessImportField[]—the fields of your records
previewnumber5the rows to show in the preview
labelsPartial<{ file: string; match: string; skip: string; required: string; previewTitle: string; rows: (count: number) => string; missing: (count: number) => string; unmatched: (fields: string) => string; import: (count: number) => string; empty: string; }>—

Events

NamePayloadDescription
import[rows: Record<string, string>[]]

Exposed

NameTypeDescription
loadText(csv: string) => void

Released under the MIT License. Character names and artwork belong to their owners.