> ## Documentation Index
> Fetch the complete documentation index at: https://hellocsv.mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Multiple Sheets

## Multiple Sheets

Often you'll want to import data that actually implicitly has multiple data schemas within it. For example, consider importing a CSV of employees working across multiple companies.

<img src="https://mintcdn.com/hellocsv/cSq31JYSfY9KO7U9/images/multiple-sheets/multiple-sheets.png?fit=max&auto=format&n=cSq31JYSfY9KO7U9&q=85&s=334ae36d9fe674ac82411c2415187741" alt="title" width="1279" height="820" data-path="images/multiple-sheets/multiple-sheets.png" />

In the above example, the company fields are actually duplicated for both Emily and Chris.

In this case, you'd most likely have a database table called `employees` and another one called `companies`, so this import should create **3 users** but only **2 companies**.

HelloCSV allows you to split the `employee` data and `company` data into separate sheets on the frontend, before the upload, to give the user a chance to review the upload and make edits.

Here is an example HelloCSV definition for the data above:

```tsx theme={null}
<Importer
  sheets={[
    {
      id: 'employees',
      label: 'Employees',
      columns: [
        { label: 'Employee ID', id: 'id', type: 'number' },
        { label: 'Employee Name', id: 'name', type: 'string', },
        {
          label: 'Company',
          id: 'company',
          type: 'reference',
          typeArguments: {
            sheetId: 'companies',
            sheetColumnId: 'name',
          },
          validators: [{ validate: 'required' }],
        },
      ],
    },
    {
      id: 'companies',
      label: 'Companies',
      columns: [
        { label: 'Company Name', id: 'name', type: 'string', validators: [{ validate: 'required' }], },
        { label: 'Company Industry', id: 'industry', type: 'string', },
      ],
    },
  ]}
  onDataColumnsMapped={(sheets: any) => {
    // Filter companies down to only unique names
    const sheet = sheets.find((sheet: any) => sheet.sheetId === 'companies')!;
    const seen = new Set();
    sheet.rows = [...sheet.rows].filter((row: SheetRow) => {
      // Remove duplicate companies
      const hasSeen = !seen.has(row.name);
      seen.add(row.name);
      return hasSeen;
    });
    return sheets;
  }}
  onComplete={async (data) => {
    const employees = data.sheetData.find((s: any) => s.id === 'employees');
    const companies = data.sheetData.find((s: any) => s.id === 'companies');
    console.log(employees);
    // [{id: 1, name: "Mat", company: "Dunder Mifflin"}, {id: 2, name: "Emily", company: "Los Pollos Hermanos"}, {id: 3, name: "Chris", company: "Los Pollos Hermanos"}]
    console.log(companies);
    // [{name: "Dunder Mifflin", industry: "Paper"}, {name: "Los Pollos Hermanos", industry: "Food & Beverage"}]
  }}
/>
```

### Screenshots

**Preview**

<img src="https://mintcdn.com/hellocsv/cSq31JYSfY9KO7U9/images/multiple-sheets/preview.png?fit=max&auto=format&n=cSq31JYSfY9KO7U9&q=85&s=52e444a6eef5e2309b45509d9464027b" width="1200" height="861" data-path="images/multiple-sheets/preview.png" />

**Mapping**

<img src="https://mintcdn.com/hellocsv/cSq31JYSfY9KO7U9/images/multiple-sheets/mapping.png?fit=max&auto=format&n=cSq31JYSfY9KO7U9&q=85&s=bf66f569ba685e1534b92f9e26c390a6" width="1200" height="862" data-path="images/multiple-sheets/mapping.png" />

**Employees Sheet**

<img src="https://mintcdn.com/hellocsv/cSq31JYSfY9KO7U9/images/multiple-sheets/employees.png?fit=max&auto=format&n=cSq31JYSfY9KO7U9&q=85&s=70b2b33c7b16f2ed25cbabb472ba25a5" width="1200" height="860" data-path="images/multiple-sheets/employees.png" />

**Companies Sheet**

<img src="https://mintcdn.com/hellocsv/cSq31JYSfY9KO7U9/images/multiple-sheets/companies.png?fit=max&auto=format&n=cSq31JYSfY9KO7U9&q=85&s=ecce64100e2383fb04bb37415ec4580d" width="1200" height="860" data-path="images/multiple-sheets/companies.png" />
