# Spreadsheets

Bring an Excel workbook, a CSV or a Google Sheet into the vault, so it lives next to your notes. Open Import notes (Ctrl K, "Import"), then drop the file or paste the sheet's link.

## Three ways in

- **Collection** (the default up to 1,000 rows): each row becomes a note, named by the first column, with the other columns as its properties. A `.base` file shows them as a table you can sort, filter and edit, like any collection. Every file is plain Markdown that Obsidian opens too. Offered up to 5,000 rows, since every note is read each time the vault opens.
- **Table**: each sheet becomes one note holding a Markdown table. Offered up to 1,000 rows, where the editor stays quick.
- **CSV file** (the default past 1,000 rows): each sheet stays one `.csv` file, which opens in a grid. Fast at any size. A CSV or TSV too long for a collection comes in as the file it was, byte for byte, without its cells being read.

The dialog only offers the layouts that stay fast for the sheet's size. A workbook with several tabs makes one collection, table note or CSV file per tab. Hidden and empty tabs are left out.

## The grid

A `.csv` or `.tsv` file opens in a grid, view only. The file is never changed.

- **Sort**: press a column's name. Up, then down, then the file's own order. Numbers come first, then text (case and accents don't count), then empty cells, which stay last going down too. Dates sort by date when they're written like `2026-12-03`.
- **Filter**: type in Filter rows to keep the rows with that text in any cell. Row numbers stay the file's own.

## Fast with massive sheets

- Files are read in a worker, off the page's thread, so the app never freezes while a workbook is read. They're handed over 4 MB at a time, since copying 75 MB in one go would hold the page for a frame or more.
- A CSV past 5,000 rows only fits the CSV layout, so on import its rows are counted, not read (`csvRowStarts`, about 0.1 s for a million rows), and the file is kept as it was.
- The grid keeps the file's own bytes plus where each row starts (4 bytes a row), and reads a row's cells only while it's on screen. A million rows use about 4 MB beside the file, instead of a string per cell.
- The first 256 KB is read on the page, so the first rows show straight away while the worker finds where the rest start. Column widths and the row-number column are set from those first rows, so nothing moves when the rest arrives.
- Only the rows and columns on screen are drawn. The same elements are used again as the grid scrolls, past React (`painter.ts`), so a row coming into view only changes the text of its cells.
- Sorting is a radix sort on the file's bytes, and filtering is one pass over them, both in the worker (which keeps a copy of the open file to do it). Typing on only looks in the rows that matched so far.
- Browsers stop drawing an element past about 17.9 million pixels (Firefox) or 33.5 million (Chromium, Safari). Past 125,000 rows the grid scrolls in a box of a fixed height (`tallScroll.ts`): the scrollbar covers more ground, and the wheel still moves one pixel for each pixel.
- Excel cells are read with plain string checks for the usual shapes (` t="s"`, `<v>…</v>`, one `<t>` run), and regular expressions only for the rest.
- A big file is written to the vault 4 MB at a time too, for the same reason.
- A collection's notes are written in one batch (`Vault.writeNew`): one index update and one event instead of one per note.

Measured on a production build in Chromium (December 2026), with no frame over 33 ms in any step:

| | Before | Now |
| --- | --- | --- |
| Import a 1,000,000-row, 77 MB CSV: read | 3.3 s | 0.8 s |
| Same file: write and open | 1.9 s | 0.85 s |
| Open it again from the vault: first rows on screen | | 0.2 s |
| Open it again: every row reachable | | 0.65 s |
| 2,000,000 rows, 150 MB: read, then write and open | | 1.3 s, 1.35 s |
| Import a 100,000-row .xlsx: read | 2.3 s | 1.3 s |
| Grid memory beside the file, 1,000,000 rows | about 100 MB | 4 MB |

Scrolling and sorting 1,000,000 rows, in headless Chrome on a Mac:

| | React rows | Painter |
| --- | --- | --- |
| Fast scroll, 240 frames: script time | 348 ms | 142 ms |
| With the CPU slowed 6 times: frames over 20 ms, of 180 | 155 | 25 |
| Sort by a column | | 0.1 to 0.4 s |
| Filter | | 0.01 to 0.3 s |

A 400-column file with the CPU slowed 6 times still drops about half its frames. 1,500,000 rows sort and reach the last row in Firefox and WebKit too.

20,000 notes write in 0.3 s in memory (58 s before the batch write).

## What comes across

- Numbers, TRUE and FALSE (as checkboxes), dates (`2026-12-03`), date and time (`2026-12-03T09:30`) and times of day. Elapsed times (`[h]:mm`) stay numbers.
- Formula results, as the spreadsheet last saved them.
- A column holding numbers and text both becomes text, so the property has one type across notes.
- Text that only looks like a number in a CSV (`00123`) stays text.
- A `Tags` column becomes note tags, split on commas.
- Column names become property names, without the characters YAML or collections can't read (`Due: date` becomes `Due date`).
- At most 1,000,000 rows and 500 columns per Excel sheet, or per CSV brought in as notes or a table. Anything past that is left out, and the dialog says so. A CSV kept as a CSV file has no limit.

Not read: formatting, colors, charts, comments, merged cells. Old `.xls`, `.ods` and Numbers files: save them as `.xlsx` first.

## Google Sheets without signing in

Hatch never signs in to Google. A link to a sheet shared as "Anyone with the link" (or published to the web) is downloaded straight from Google by your device, as `.xlsx`. Nothing goes through a Hatch server.

A private sheet can't be read that way. Either share it with the link, or choose File, Download, Microsoft Excel and drop the file in. Reading private sheets would need Hatch to ask for Google access to your Drive, which we left out on purpose.

It's a one-time copy: changes in Google later don't flow in. Import again to get a fresh copy.

## Code

- `packages/import/src/sheets.ts`: the .xlsx reader (on the zip reader), CSV and TSV, Google links, and turning sheets into files.
- `packages/app/src/sheets/`: the worker (`sheetWorker.ts`), what it does (`protocol.ts`), the page's side (`reader.ts`) and the grid's file reading (`grid.ts`).
- `packages/app/src/components/Import.tsx`: the dialog (the layout choice and the link field). `components/CsvGrid.tsx`: the grid for .csv and .tsv files, with `sheets/painter.ts` (rows on screen) and `sheets/tallScroll.ts` (scrolling). Cells, sorting and filtering from bytes: `packages/import/src/csvBytes.ts` and `csvView.ts`.
- Tests: `packages/import/src/sheets.test.ts` with workbooks saved by openpyxl and LibreOffice in `packages/import/fixtures/`, `packages/app/src/sheets/grid.test.ts`, and `scripts/e2e-import.py` (a 100,000-row CSV through the grid).

## Samples

- `fixtures/sample-sheets/Trail store.xlsx`: a workbook with three tabs (products, 2,000 orders, a team list) to try the import with.
- The showcase vault (`VITE_HATCH_STARTER=showcase`) has it already imported: `Trail store/Products.base` as a collection, `Data/Orders.csv`, and `Data/Trail sensor log.csv`, 250,000 rows made on the device when the vault is created (`sensorLog` in `packages/starter`).
