# Troubleshooting

> Fix a spreadsheet that does not fill its container,

Formula problems show up in the cells as Excel-style errors. Component problems are reported through the `error` event and in the console with the prefix `[Birch UI Spreadsheet]`.

| Symptom | Jump to |
| --- | --- |
| The sheet is 480 pixels tall whatever the container | [The spreadsheet does not fill its container](#the-spreadsheet-does-not-fill-its-container) |
| Cells, headers and the formula bar are unstyled | [The spreadsheet has no styles](#the-spreadsheet-has-no-styles) |
| A formula shows `#NAME?` | [A formula shows #NAME?](#a-formula-shows-name) |
| A formula with `;` separators is rejected | [A formula shows #NAME?](#a-formula-shows-name) |
| A formula shows `#SPILL!` | [A formula shows #SPILL!](#a-formula-shows-spill) |
| A formula shows `#BLOCKED!` | [A formula shows #BLOCKED!](#a-formula-shows-blocked) |
| A picture is an empty dashed frame | [A picture is an empty frame](#a-picture-is-an-empty-frame) |
| Cells show 0 and an `error` event reports `circularReference` | [A circular reference shows 0](#a-circular-reference-shows-0) |
| Conditional formats or validation disappear after an xlsx round trip | [Formatting is lost in xlsx files](#formatting-is-lost-in-xlsx-files) |
| Excel opens a spilling formula as a single value | [Formatting is lost in xlsx files](#formatting-is-lost-in-xlsx-files) |
| A date shows as a number such as `46096` | [Dates show as numbers](#dates-show-as-numbers) |
| Typing is slow in a large workbook | [Recalculation is slow](#recalculation-is-slow) |
| "Birch UI Spreadsheet · unlicensed copy" in the corner | [A watermark appears](#a-watermark-appears) |
| `Refused to apply inline style` in the console | [A Content Security Policy blocks the styles](#a-content-security-policy-blocks-the-styles) |
| Two copies of a package, or a large bundle | [Duplicate packages and bundle size](#duplicate-packages-and-bundle-size) |
| Problems only in React, Vue, Svelte or Angular | [Framework adapters](#framework-adapters) |

## The spreadsheet does not fill its container

**Cause.** Unlike the grid, the spreadsheet does not take its container's height. Without a `height` option it is 480 pixels tall, with a minimum of 200.

**Fix.** Pass `height` as pixels or any CSS length. Use `'100%'` to fill a container that has a height:

```ts
createSpreadsheet(document.querySelector<HTMLElement>('#loan-model')!, {
  data: loanModel,
  height: '100%',
});
```

## The spreadsheet has no styles

**Cause.** With `injectStyles: false`, the spreadsheet does not add its stylesheet.

**Fix.** Import `@birchui/spreadsheet/styles.css`, or insert the exported `spreadsheetStyles` string into a shadow root yourself. See [Importing the CSS file](https://docs.birchui.com/getting-started/installation.md#importing-the-css-file).

## A Content Security Policy blocks the styles

**Cause.** Injected styles are a `<style>` element, which a `style-src` policy without `'unsafe-inline'` blocks. The injected element has no nonce option.

**Fix.** Set `injectStyles: false` and import `@birchui/spreadsheet/styles.css` through your bundler.

## A formula shows #NAME?

**Cause.** `#NAME?` means an unknown function or name, or syntax the parser does not support:

- a function outside the built-in list, such as `LINEST`, `T.DIST`, `CUBEVALUE` or `HYPERLINK`;
- a misspelled defined name;
- a structured table reference such as `Orders[Amount]`, a 3-D reference such as `SUM(Jan:Dec!B5)`, or an R1C1 reference;
- localized syntax, such as `=SUMME(A1;A2)` or `=ROUND(B4;2)`.

**Fix.** Check the [function reference](https://docs.birchui.com/spreadsheet/functions.md) and write formulas in the en-US syntax Excel stores in files: commas between arguments and English names. Replace table references with ranges or [defined names](https://docs.birchui.com/spreadsheet/formulas.md#defined-names), and add missing calculations as `LAMBDA` functions in defined names. See [Formula language](https://docs.birchui.com/spreadsheet/limitations.md#formula-language).

## A formula shows #SPILL!

**Cause.** A formula that returns several values, such as `=FILTER(...)` or `=SEQUENCE(12)`, spills into the cells below and to the right. When a value already sits in that range, including one typed there later, the anchor shows `#SPILL!`.

**Fix.** Clear the cells in the way; the results come back automatically. The `A1#` spill operator is not supported, so refer to the range directly or wrap the formula in `INDEX` or `TAKE`. Set `dynamicArrays: false` for the implicit intersection of older Excel versions. See [Dynamic arrays and spilling](https://docs.birchui.com/spreadsheet/formulas.md#dynamic-arrays-and-spilling).

## A formula shows #BLOCKED!

**Cause.** The formula uses `IMAGE` with a web address. The spreadsheet makes no network requests, so it cannot load the picture itself.

**Fix.** Pass a `resolveImage` function that returns a `data:` or `blob:` URL for the addresses you trust, from pictures you fetched beforehand. It is not called in worker calculation. See [The IMAGE function](https://docs.birchui.com/spreadsheet/images.md#the-image-function).

## A picture is an empty frame

**Cause.** The picture is in a format the spreadsheet stores but cannot draw: a TIFF with Deflate, JPEG or CCITT compression, tiles or 16-bit samples, or a metafile it cannot read. A picture whose `src` is a web address is not loaded either.

**Fix.** The file is intact and is written back unchanged, so Excel still shows it. To see it here, convert it to PNG before adding it, or use a `data:` URL. See [Formats](https://docs.birchui.com/spreadsheet/images.md#formats).

## A circular reference shows 0

**Cause.** A formula that depends on itself, directly or through other cells, is circular. The cells involved show 0 and the spreadsheet emits an `error` event with the code `circularReference`.

**Fix.** Break the loop, or turn on iterative calculation for models that are circular by design:

```ts
createSpreadsheet(container, {
  data: treasuryModel,
  iterativeCalculation: { maxIterations: 200, maxChange: 0.0001 },
});

sheet.on('error', ({ code, address }) => {
  if (code === 'circularReference') showNotice(`Circular reference at ${address}`);
});
```

See [Circular references](https://docs.birchui.com/spreadsheet/formulas.md#circular-references).

## Formatting is lost in xlsx files

**Cause.** Most formatting round-trips, including conditional formatting, data validation, strikethrough and dynamic arrays. What can go missing is narrower: a conditional formatting rule that exists only in the Excel 2010 extension and is not an icon set is kept in the file but not applied, and another program that saves the file in between may drop features of its own accord, as [LibreOffice and openpyxl do](https://docs.birchui.com/spreadsheet/xlsx.md#conditional-formatting-in-files) with some data bar and icon set options. A file saved as `.ods` or `.csv` carries far less than xlsx.

**Fix.** Call `getImportReport()` after `importXlsx()`, or open **Review > Import report**, to see what a file kept and lost. Store the workbook JSON from `toJSON()` alongside the file when users rely on a feature that is not carried. See [What round-trips](https://docs.birchui.com/spreadsheet/xlsx.md#what-round-trips) and [what an ods file carries](https://docs.birchui.com/spreadsheet/file-formats.md#what-an-ods-file-carries).

## Dates show as numbers

**Cause.** Dates are serial numbers in the 1900 date system. A serial without a date number format shows as a number. Typed dates are read month first, as in en-US.

**Fix.** Give the cell a date number format, or pass a `Date` to `setValue()`, which stores a serial. Convert in code with `dateToSerial()` and `serialToDate()`, which work in UTC. See [Dates and times](https://docs.birchui.com/spreadsheet/formulas.md#dates-and-times).

## Recalculation is slow

**Cause.** Volatile functions (`NOW`, `TODAY`, `RAND`, `OFFSET`, `INDIRECT` and others) recalculate on every change. A loop of `setValue()` calls recalculates after each one, thousands of copied formulas are thousands of graph nodes, and calculation runs on the page's main thread.

**Fix.** Put `TODAY()` in one cell and refer to it, prefer `INDEX` to `OFFSET`, batch changes with `setRange()`, spill one formula instead of copying it down, and import xlsx files with `xlsxToJSON()` in a Web Worker. See [Advice for large workbooks](https://docs.birchui.com/spreadsheet/performance.md#advice-for-large-workbooks).

## A watermark appears

**Cause.** The spreadsheet checks its key for `spreadsheet` offline. On a non-local host with no valid key, a watermark appears and one warning is logged, for example:

```text
[Birch UI] No license key is set for Birch UI Spreadsheet. All features keep working; a watermark is shown on non-local hosts until a valid license key is set. Purchase a license at https://birchui.com/pricing
```

**Fix.** Call `setLicenseKey` from `@birchui/license` in the browser bundle, or pass `licenseKey` to `createSpreadsheet`. With server rendering, expose the key through a public variable such as `NEXT_PUBLIC_BIRCHUI_LICENSE_KEY`; see [The license key is not applied with server rendering](https://docs.birchui.com/frameworks/troubleshooting.md#the-license-key-is-not-applied-with-server-rendering) and [What happens without a valid key](https://docs.birchui.com/getting-started/licensing.md#what-happens-without-a-valid-key).

## Duplicate packages and bundle size

**Cause.** Two installed versions of `@birchui/core` or `@birchui/license` split their state, so a key set in one copy is not seen by the other.

**Fix.** Run `npm ls @birchui/core @birchui/license`, align all `@birchui/*` packages on one version and run `npm dedupe`, or add `overrides` in `package.json`. Load the spreadsheet with a dynamic `import()` on the pages that need it; see [Bundle size](https://docs.birchui.com/spreadsheet/performance.md#bundle-size).

## Framework adapters

Wrap the spreadsheet with `createReactComponent(spreadsheetDefinition)` or the equivalent factory. Passing a new `data` object on every render reloads the workbook and clears the undo history, so load it once and read changes from `cellChange` events or `toJSON()`. See [Framework troubleshooting](https://docs.birchui.com/frameworks/troubleshooting.md), in particular [The widget updates on every render](https://docs.birchui.com/frameworks/troubleshooting.md#the-widget-updates-on-every-render) and [The widget is created twice in development](https://docs.birchui.com/frameworks/troubleshooting.md#the-widget-is-created-twice-in-development).

## Related

- [API reference: @birchui/spreadsheet](https://docs.birchui.com/api/spreadsheet.md)
- [Limitations](https://docs.birchui.com/spreadsheet/limitations.md)
