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
fieldsis the list of your fields. Each field has akey, alabel, and an optionalrequired.- 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
importwith 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
parseCsvfunction is exported. - Change the words with
labelsor a label pack:file,match,skip,required,previewTitle,empty, and the functionsrows,missing,unmatched, andimport.
Usage
ts
import { BlessCsvImport } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
fields* | BlessImportField[] | — | the fields of your records |
preview | number | 5 | the rows to show in the preview |
labels | Partial<{ 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
| Name | Payload | Description |
|---|---|---|
import | [rows: Record<string, string>[]] |
Exposed
| Name | Type | Description |
|---|---|---|
loadText | (csv: string) => void |