Integrate in Astro

Before you begin, read installation and basic usage. The example below mounts Univer Sheets in a container with an explicit height on an Astro page.

Initialize the editor from a plain <script> element so that the code runs in the browser. Run the initialization on the first load and again on astro:page-load, and dispose of the editor before astro:before-swap when ClientRouter is enabled. Keep editor imports out of the Astro frontmatter. For details, see Astro navigation events.

Integration steps

  1. Initialize Univer in mount() and on astro:page-load.
  2. Dispose of Univer in astro:before-swap.

Preset configuration

UniverSheetsCorePreset

  • container
    string | HTMLElementDefault: 'app'
    The element into which Univer is mounted, or the DOM ID of that element.

Example

Astro
<div id="univer-sheets" style="height: 600px"></div><script>  import type { Univer } from '@univerjs/presets'  import { UniverSheetsCorePreset } from '@univerjs/preset-sheets-core'  import UniverPresetSheetsCoreenUS from '@univerjs/preset-sheets-core/locales/en-US'  import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'  import '@univerjs/preset-sheets-core/lib/index.css'  let univerInstance: Univer | undefined  function mount() {    const container = document.getElementById('univer-sheets')    if (!container || univerInstance) return    const { univer, univerAPI } = createUniver({      locale: LocaleType.EN_US,      locales: { [LocaleType.EN_US]: mergeLocales(UniverPresetSheetsCoreenUS) },      presets: [UniverSheetsCorePreset({ container })],    })    univerAPI.createWorkbook({})    univerInstance = univer  }  function dispose() {    univerInstance?.dispose()    univerInstance = undefined  }  mount()  document.addEventListener('astro:page-load', mount)  document.addEventListener('astro:before-swap', dispose)</script>

How is this guide?

© 2026 DreamNum Co., Ltd.