Import Mapper
The mapping step of a spreadsheet import: match each column of the file to a field, check the required ones, then preview the rows with their errors.
Presets
Looks and jobs for c2-import-mapper. The summary chips (__field__mapped--*, __field__missing--*), the column row (__column--*, __sample--*) and the preview’s invalid cell (__cell__invalid--background-color, __error--color) do most of the work. The last cards wire properties from script: the renderers, a dataSource and a translation.
- Name, mapped
- Email, mapped
All required fields are mapped 4 of 5 columns mapped
-
Full name Auto-matchedAda LovelaceGrace HopperAlan TuringDon't import
Don't import NameRequiredName EmailRequiredEmail PhonePhone Customer sinceCustomer since -
E-mail address Auto-matchedada@analytical.iograce@navy.milalan@bletchley.orgDon't import
Don't import NameRequiredName EmailRequiredEmail PhonePhone Customer sinceCustomer since -
Phone # Auto-matched+44 20 7946 0000+44 161 496 0000Don't import
Don't import NameRequiredName EmailRequiredEmail PhonePhone Customer sinceCustomer since -
Signed up Auto-matched2024-03-012024-04-122024-05-17Don't import
Don't import NameRequiredName EmailRequiredEmail PhonePhone Customer sinceCustomer since -
Notes Not importedVIPCall backDon't import
Don't import NameRequiredName EmailRequiredEmail PhonePhone Customer sinceCustomer since
- SKU, not mapped
- Title, not mapped
- Price, not mapped
3 required fields are not mapped: SKU, Title, Price 0 of 3 columns mapped
-
Product Not importedDesk lampMonitor armDon't import
Don't import SKURequired · Unique product codeSKU TitleRequiredTitle PriceRequiredPrice StockStock -
Cost Not imported49.9089.00Don't import
Don't import SKURequired · Unique product codeSKU TitleRequiredTitle PriceRequiredPrice StockStock -
Qty on hand Not imported12035Don't import
Don't import SKURequired · Unique product codeSKU TitleRequiredTitle PriceRequiredPrice StockStock
4 rows, 2 with errors (5 errors)
| Row | Invoice | Customer | Amount | Due | Status |
|---|---|---|---|---|---|
| 1 | INV-1041 | Northwind | 1 250,00 | 2024-07-01 | sent |
| 2 | INV-1042 | Error: Required | 980.50 | 2024-07-15 | paid |
| 3 | INV-104 Error: Not in the expected format | Contoso | twelve Error: Not a number | 2024-02-30 Error: Not a date | overdue Error: Must be one of: draft, sent, paid |
| 4 | INV-1044 | Fabrikam | 310 | 2024-08-01 | draft |
5 rows, 2 with errors (3 errors)
| Row | Invoice | Customer | Amount |
|---|---|---|---|
| 2 | INV-1042 | Error: Required | 980.50 |
| 3 | INV-104 Error: Not in the expected format | Contoso | twelve Error: Not a number |
- Email, mapped
All required fields are mapped 3 of 3 columns mapped
-
Email Auto-matchedkim@acme.iosam@acme.iojo@acmeDon't import
Don't import EmailRequiredEmail NameName RoleRole -
Full name Auto-matchedKim LeeSam OrtizJo ParkDon't import
Don't import EmailRequiredEmail NameName RoleRole -
Role Auto-matchedadmineditorviewerDon't import
Don't import EmailRequiredEmail NameName RoleRole
- Date, mapped
- Amount, mapped
All required fields are mapped 3 of 4 columns mapped
-
Date Auto-matched2024-06-032024-06-04Don't import
Don't import DateRequiredDate DescriptionDescription AmountRequiredAmount -
Memo Auto-matchedCoffee beansSalaryDon't import
Don't import DateRequiredDate DescriptionDescription AmountRequiredAmount -
Amount Auto-matched-18.402400.00Don't import
Don't import DateRequiredDate DescriptionDescription AmountRequiredAmount -
Balance Not imported1203.103603.10Don't import
Don't import DateRequiredDate DescriptionDescription AmountRequiredAmount
- Company, mapped
All required fields are mapped 3 of 3 columns mapped
-
Account Auto-matchedNorthwindContosoDon't import
Don't import CompanyRequiredCompany ContactContact Deal valueDeal value -
Lead name Auto-matchedNancy DavolioKim AbercrombieDon't import
Don't import CompanyRequiredCompany ContactContact Deal valueDeal value -
Amount Auto-matched120008400Don't import
Don't import CompanyRequiredCompany ContactContact Deal valueDeal value
4 rows, 1 with errors (1 error)
| Row | Date | Payee | Amount |
|---|---|---|---|
| 1 | 2024-06-03 | Blue Bottle | -18.40 |
| 2 | 2024-06-04 | Acme Payroll | 2400 |
| 3 | 2024-06-05 | City Power | -96.12 |
| 4 | 2024-06-06 | Refund | n/a Error: Not a number |
0 rows, no errors
- Nom, mapped
- E-mail, mapped
All required fields are mapped 2 of 3 columns mapped
-
Nom complet Auto-matchedMarie CurieLouis PasteurDon't import
Don't import NomRequiredNom E-mailRequiredE-mail VilleVille -
Courriel Auto-matchedmarie@sorbonne.frlouis@pasteur.frDon't import
Don't import NomRequiredNom E-mailRequiredE-mail VilleVille -
Notes Not importedPrix NobelDon't import
Don't import NomRequiredNom E-mailRequiredE-mail VilleVille
The renderer card draws each column’s samples and each preview cell from script. The component keeps the cell, its error tint and its message:
import { html } from 'lit'
import type { ImportMapper } from '@c2n/components/import-mapper'
const money = new Intl.NumberFormat('en', { style: 'currency', currency: 'USD' })
mapper.renderSamples = ({ values }) => html`<span>${values.length} values, e.g. <b>${values[0]}</b></span>`
mapper.renderCell = ({ value, field, error }) =>
field.key === 'amount' && !error ? html`<span style="color:${Number(value) < 0 ? '#b91c1c' : '#15803d'}">${money.format(Number(value))}</span>` : valueThe data source card reads 240 orders a page at a time, after a short delay, as a server would:
mapper.columns = ['Order', 'Customer', 'Total']
mapper.dataSource = {
async getRows({ start, count }) {
const { rows, total } = await fetch(`/imports/42/rows?start=${start}&count=${count}`).then((r) => r.json())
return { rows, total } // rows: arrays of cells, or records keyed by header
},
}The French card registers its text once for the app:
import { addTranslations } from '@c2n/core/localize.js'
addTranslations({ fr: { 'import-mapper': { skip: 'Ne pas importer', auto: 'Associée', pickerLabel: 'Importer la colonne « {0} » comme' /* … */ } } })