Spreadsheet
A spreadsheet with its own formula engine and no dependency: A1 references, sixty-three functions and recalculation of only what changed.
Import
import { Spreadsheet } from '@vitral/vue';Default
Type into it, drag the handle at the corner of the selection to fill, and watch the totals follow. Start a formula — `=B2*C2` — and each cell it reads is outlined where it sits.
What comes back
`v-model` is what was typed, keyed by A1 — the formulas are formulas, not what they worked out to.
What is kept for D8 is =D6+D7, and it reads £1,341.60 — edit a price above and both follow.
Formulas
Sixty-three of them: SUM, AVERAGE, MIN, MAX, COUNT and COUNTIF, IF and IFERROR, the text ones, INDEX, MATCH and VLOOKUP, and dates as the days every spreadsheet counts in.
When a formula cannot answer
An error is a value: it travels through arithmetic, and `IFERROR` catches it.
The toolbar
`toolbar` takes groups of item names, or `false` for none; the `toolbar` slot replaces the bar with parts of your own. Every tool acts on the selected rectangle, and the pressed ones read the cell the caret is in.
Read only
`readonly` leaves the keyboard and the selection, and takes the typing and the fill handle away.
Where the keyboard is
`selection-change` says which cell, or which rectangle, every time it moves.
Selected: A1
API
Read from packages/vue/src/components/Spreadsheet/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| modelValue | Record<string, string | number | boolean | null> | The cells, keyed by A1: `{ A1: 'Sales', B2: 42, B3: '=B2*2' }`. What is kept is what was typed, so a formula survives a round trip. |
| rows | number | How many rows and columns the grid offers. |
| columns | number | — |
| formats | Record<string, CellFormatLike> | Formats, by A1 or by a rectangle: `{ 'B2:B9': { kind: 'currency' } }`. |
| columnWidths | Record<string, number> | Widths in pixels by column letter; the reader's own resizing goes here too. |
| rowHeights | Record<number, number> | Heights in pixels by row number, as a person counts them. |
| toolbar | boolean | SpreadsheetToolbarItemLike[][] | The bar of tools over the grid: `false` for none, or groups of item names. The `toolbar` slot replaces the bar with parts of your own. |
| formulaBar | boolean | The bar over the grid that shows the address and the formula. On by default. |
| currency | string | The currency a cell formatted as money is written in. Defaults to the locale's. |
| readonly | boolean | Nothing can be typed into it. |
| ariaLabel | string | Names the grid, where no label points at it. |
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Slots
| Name | Slot props | Description |
|---|---|---|
| toolbar | — | Replaces the bar of tools over the grid. |