Headless Univer

Headless Univer is the part of Univer that handles content without an interactive editor UI. It shares content models, commands, calculation, and the Facade API with the browser editor. It runs in Node.js, or in a browser for tasks that need no UI. Its capabilities depend on the product and feature plugins you register.

In Node.js, Headless Univer creates or loads a workbook, reads and writes cells and formatting, changes rows and columns, calculates formulas, and saves a Univer snapshot. Filtering, sorting, validation, pivot tables, and charts work only when the matching content plugins are registered. Changing chart data does not render the chart.

The example below uses plugin mode. @univerjs/core and the product content plugins belong to the Headless content layer; @univerjs/ui, the product *-ui packages, and the default browser core presets do not. The example still depends on @univerjs/engine-render, but it never mounts a Canvas or an editor. Headless package boundaries lists the complete classification and the exceptions.

Local snapshot operations do not require a collaboration service. The collaboration example additionally requires a client, a server, and authentication. Office conversion requires Server SDK, and screenshots require a rendering runtime. Importing /facade alone registers no feature plugins, and it does not turn UI APIs into Headless APIs.

Installation

Shell
pnpm add @univerjs/core @univerjs/engine-render @univerjs/engine-formula @univerjs/docs @univerjs/sheets @univerjs/sheets-formula @univerjs/sheets-numfmt

Usage

TypeScript
import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { FUniver } from '@univerjs/core/facade'import { UniverDocsPlugin } from '@univerjs/docs'import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'import { UniverRenderEnginePlugin } from '@univerjs/engine-render'import { UniverSheetsPlugin } from '@univerjs/sheets'import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula'import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt'import SheetsEnUS from '@univerjs/sheets/locale/en-US'import '@univerjs/engine-formula/facade'import '@univerjs/sheets/facade'import '@univerjs/sheets-formula/facade'import '@univerjs/sheets-numfmt/facade'const univer = new Univer({  locale: LocaleType.EN_US,  locales: {    [LocaleType.EN_US]: mergeLocales(      SheetsEnUS,    ),  },})univer.registerPlugin(UniverRenderEnginePlugin)univer.registerPlugin(UniverFormulaEnginePlugin)univer.registerPlugin(UniverDocsPlugin)univer.registerPlugin(UniverSheetsPlugin)univer.registerPlugin(UniverSheetsFormulaPlugin)univer.registerPlugin(UniverSheetsNumfmtPlugin)const univerAPI = FUniver.newAPI(univer)univerAPI.createWorkbook({})

Collaborative editing in Node.js

Node.js can also act as a collaboration client. It loads an existing workbook from the server, changes it through the Facade API, and synchronizes those changes to every other client that has the same document open. Set up a collaboration service and a client license before running the example, and prepare a document ID that is accessible.

Plugin configuration

UniverLicensePlugin

  • license
    string
    Contents of the client license file.

UniverDrawingPlugin

  • override
    [DependencyIdentifier, Provider | null][]
    Dependency overrides for the drawing plugin.
    • [0]
      DependencyIdentifier
      Dependency identifier. Use IImageIoService for image storage.
    • [1]
      Provider | null
      Replacement provider. Pass null to have collaboration provide this service.

UniverRPCNodeMainPlugin

  • workerSrc
    string
    Path to the Node.js calculation Worker entry file.

UniverProFormulaEnginePlugin

  • notExecuteFormula
    boolean
    Skip formula calculation in the current runtime when a Worker handles it.

UniverSheetsFormulaPlugin

  • notExecuteFormula
    boolean
    Skip formula calculation in the current runtime when a Worker handles it.

UniverSheetsPivotTablePlugin

  • notExecuteFormula
    boolean
    Selects the role for pivot calculation. Set it to true on the main thread and to false in the Worker. Omit it for single-threaded use.

UniverSheetsPlugin

  • notExecuteFormula
    boolean
    Skip formula calculation in the current runtime when a Worker handles it.
  • onlyRegisterFormulaRelatedMutations
    boolean
    Register only mutations needed by formula calculation.

UniverCollaborationClientPlugin

  • socketService
    Ctor<ICollaborationSocketService>
    Select the socket implementation for the current runtime.
  • enableOfflineEditing
    booleanDefault: false
    Allows local edits while offline.
  • enableSingleActiveInstanceLock
    booleanDefault: false
    Limits active editing of a document to one browser instance.
  • snapshotServerUrl
    stringDefault: '/universer-api/snapshot'
    Endpoint for loading document snapshots.
  • collabSubmitChangesetUrl
    stringDefault: '/universer-api/comb'
    Endpoint for submitting changesets.
  • collabWebSocketUrl
    stringDefault: 'ws://127.0.0.1:8000/universer-api/comb/connect'
    WebSocket endpoint for realtime changes.
  • wsSessionTicketUrl
    stringDefault: '/universer-api/user/session-ticket'
    Endpoint for obtaining a WebSocket session ticket.
  • uploadFileServerUrl
    stringDefault: '/universer-api/stream/file/upload'
    Endpoint for uploading files.
  • signUrlServerUrl
    stringDefault: '/universer-api/file/{fileID}/sign-url'
    Endpoint for signing file URLs. Keep the {fileID} placeholder.
  • downloadEndpointUrl
    string
    Base URL for downloading files.
  • authzUrl
    stringDefault: '/universer-api/authz'
    Endpoint for permission checks.
  • sendChangesetTimeout
    numberDefault: 2000
    Batching delay in milliseconds before edits are sent.
  • retryConnectingInterval
    numberDefault: 20000
    Reconnect interval in milliseconds.
  • customHeaders
    Record<string, string>
    Extra headers for the connection.
    • [header]
      string
      Value sent for this HTTP header.

Example files

Lay the files out as follows:

text
src/sheets/node/├── main.ts├── univer.ts└── worker.ts
  • univer.ts creates Univer, registers the feature plugins, the collaboration client, and the optional RPC main-process plugin.
  • worker.ts registers the formula engine on the calculation side, the remote formula, filter, and pivot table plugins, and communicates with the main process over RPC.
  • main.ts loads the collaborative document and demonstrates permissions, basic sheet operations, conditional formatting, data validation, tables, pivot tables, sparklines, images, charts, shapes, grouping, and hyperlinks.

Replace your-license in both files with the same license, and update the server URL, Cookie, document ID, and user IDs. The permission example in main.ts also configures collaborators and protected ranges, which requires real application users and an identity with the necessary management permissions.

TypeScript
import { UniverCollaborationPlugin } from '@univerjs-pro/collaboration'import { UniverCollaborationClientPlugin } from '@univerjs-pro/collaboration-client'import {  NodeCollaborationSocketService,  UniverCollaborationClientNodePlugin,} from '@univerjs-pro/collaboration-client-node'import { UniverProFormulaEnginePlugin } from '@univerjs-pro/engine-formula'import { UniverLicensePlugin } from '@univerjs-pro/license'import { UniverSheetsChartPlugin } from '@univerjs-pro/sheets-chart'import { UniverSheetsOutlinePlugin } from '@univerjs-pro/sheets-outline'import { UniverSheetsPivotTablePlugin } from '@univerjs-pro/sheets-pivot'import { UniverSheetsShapePlugin } from '@univerjs-pro/sheets-shape'import { UniverSheetSparklinePlugin } from '@univerjs-pro/sheets-sparkline'import { IAuthzIoService, IImageIoService, IUndoRedoService, LocaleType, Univer } from '@univerjs/core'import { UniverDataValidationPlugin } from '@univerjs/data-validation'import { UniverDocsPlugin } from '@univerjs/docs'import { UniverDocsDrawingPlugin } from '@univerjs/docs-drawing'import { UniverDrawingPlugin } from '@univerjs/drawing'import { UniverRenderEnginePlugin } from '@univerjs/engine-render'import { UniverNetworkPlugin } from '@univerjs/network'import { UniverRPCNodeMainPlugin } from '@univerjs/rpc-node'import { UniverSheetsPlugin } from '@univerjs/sheets'import { UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting'import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation'import { UniverSheetsDrawingPlugin } from '@univerjs/sheets-drawing'import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter'import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula'import { UniverSheetsHyperLinkPlugin } from '@univerjs/sheets-hyper-link'import { UniverSheetsNotePlugin } from '@univerjs/sheets-note'import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt'import { UniverSheetsSortPlugin } from '@univerjs/sheets-sort'import { UniverSheetsTablePlugin } from '@univerjs/sheets-table'import { UniverThreadCommentPlugin } from '@univerjs/thread-comment'import path from 'node:path'// The Facade APIs used here are part of packages/facade/src/apis/everything.ts// Some plugin implementations are incomplete, so their APIs are not included here.import '@univerjs/engine-formula/facade'import '@univerjs/sheets/facade'import '@univerjs/sheets-formula/facade'import '@univerjs/sheets-numfmt/facade'import '@univerjs/sheets-conditional-formatting/facade'import '@univerjs/sheets-data-validation/facade'import '@univerjs/sheets-filter/facade'import '@univerjs/sheets-hyper-link/facade'import '@univerjs/sheets-note/facade'import '@univerjs/sheets-table/facade'import '@univerjs/sheets-drawing/facade'import '@univerjs/sheets-thread-comment/facade'import '@univerjs-pro/engine-shape/facade'import '@univerjs-pro/sheets-pivot/facade'import '@univerjs-pro/sheets-sparkline/facade'import '@univerjs-pro/sheets-chart/facade'import '@univerjs-pro/sheets-shape/facade'import '@univerjs-pro/sheets-outline/facade'import '@univerjs-pro/collaboration-client/facade'export interface ICreateUniverOnNodeOptions {  useComputingWorker?: boolean}export function createUniverOnNode(options: ICreateUniverOnNodeOptions = {}): Univer {  const { useComputingWorker = false } = options  const univer = new Univer({    locale: LocaleType.EN_US,    locales: {},    override: [      [IAuthzIoService, null],      [IUndoRedoService, null],    ],  })  univer.registerPlugin(UniverLicensePlugin, {    license: 'your-license',  })  registerBasicPlugins(univer, useComputingWorker)  registerSharedPlugins(univer)  if (useComputingWorker) {    registerRPCPlugin(univer)  }  registerDocPlugins(univer)  registerSheetPlugins(univer, useComputingWorker)  registerCollaborationPlugins(univer)  return univer}function registerBasicPlugins(univer: Univer, useComputingWorker: boolean): void {  univer.registerPlugin(UniverProFormulaEnginePlugin, { notExecuteFormula: useComputingWorker })}function registerSharedPlugins(univer: Univer): void {  univer.registerPlugin(UniverRenderEnginePlugin)  univer.registerPlugin(UniverThreadCommentPlugin)  univer.registerPlugin(UniverDrawingPlugin, {    override: [[IImageIoService, null]],  })}function registerDocPlugins(univer: Univer): void {  univer.registerPlugin(UniverDocsPlugin)  univer.registerPlugin(UniverDocsDrawingPlugin)}function registerSheetPlugins(univer: Univer, useComputingWorker: boolean): void {  univer.registerPlugin(UniverSheetsPlugin, { notExecuteFormula: useComputingWorker })  univer.registerPlugin(UniverSheetsFormulaPlugin, { notExecuteFormula: useComputingWorker })  univer.registerPlugin(UniverSheetsNumfmtPlugin)  univer.registerPlugin(UniverSheetsConditionalFormattingPlugin)  univer.registerPlugin(UniverDataValidationPlugin)  univer.registerPlugin(UniverSheetsDataValidationPlugin)  univer.registerPlugin(UniverSheetsFilterPlugin)  univer.registerPlugin(UniverSheetsHyperLinkPlugin)  univer.registerPlugin(UniverSheetsNotePlugin)  univer.registerPlugin(UniverSheetsDrawingPlugin)  univer.registerPlugin(UniverSheetsSortPlugin)  univer.registerPlugin(UniverSheetsTablePlugin)  univer.registerPlugin(UniverSheetsChartPlugin)  univer.registerPlugin(UniverSheetsShapePlugin)  univer.registerPlugin(UniverSheetsPivotTablePlugin, {    notExecuteFormula: useComputingWorker ? true : undefined,  })  univer.registerPlugin(UniverSheetSparklinePlugin)  univer.registerPlugin(UniverSheetsOutlinePlugin)}function registerRPCPlugin(univer: Univer): void {  // Set the worker path to the actual location of the build output.  const childPath = path.join(__dirname, 'worker.js')  univer.registerPlugin(UniverRPCNodeMainPlugin, { workerSrc: childPath })}function registerCollaborationPlugins(univer: Univer): void {  const serverUrl = 'https://your-univer-server.example.com'  univer.registerPlugin(UniverNetworkPlugin)  univer.registerPlugin(UniverCollaborationPlugin)  univer.registerPlugin(UniverCollaborationClientPlugin, {    socketService: NodeCollaborationSocketService,    enableOfflineEditing: false,    enableSingleActiveInstanceLock: false,    snapshotServerUrl: `${serverUrl}/universer-api/snapshot`,    collabSubmitChangesetUrl: `${serverUrl}/universer-api/comb`,    collabWebSocketUrl: `${serverUrl}/universer-api/comb/connect`,    wsSessionTicketUrl: `${serverUrl}/universer-api/user/session-ticket`,    uploadFileServerUrl: `${serverUrl}/universer-api/stream/file/upload`,    signUrlServerUrl: `${serverUrl}/universer-api/file/{fileID}/sign-url`,    downloadEndpointUrl: `${serverUrl}`,    authzUrl: `${serverUrl}/universer-api/authz`,    sendChangesetTimeout: 200,    retryConnectingInterval: 1000,    customHeaders: {      // Example: If your Univer server requires authentication via cookies, you can set the 'cookie' header here.      cookie: 'your-cookie',      // ... more headers    },  })  univer.registerPlugin(UniverCollaborationClientNodePlugin)}

Enable the calculation worker

createUniverOnNode() defaults to useComputingWorker: false, so formulas are calculated in the current process. The main.ts example above passes useComputingWorker: true, which enables the calculation worker:

  1. In the main process, UniverProFormulaEnginePlugin, UniverSheetsPlugin, UniverSheetsFormulaPlugin, and UniverSheetsPivotTablePlugin all set notExecuteFormula: true, which transfers calculation to the child process over RPC.
  2. UniverRPCNodeMainPlugin starts the built worker.js referenced by workerSrc.
  3. The child process receives the data and performs the calculation through UniverRPCNodeWorkerPlugin and UniverRemoteSheetsFormulaPlugin.

UniverSheetsPivotTablePlugin treats this option differently depending on where it runs. With a worker, set it to true in the main process and to false in the worker. Without a worker, omit the option or set it to undefined; the pivot table services and the calculation logic are then registered in the current process. For this reason, the main process passes useComputingWorker ? true : undefined rather than useComputingWorker directly.

Node.js starts the worker with child_process.fork(). Build main.ts and worker.ts as separate entry points with the build tool already in use, then point workerSrc at the built worker file. The example assumes that worker.js resides in the same directory as the main entry output, so adjust the path, extension, and module format to match the build output. The example locates the file through CommonJS __dirname; an ESM project requires the corresponding path resolution.

Runtime notes

loadSheetAsync() loads a document that already exists on the server, so calling createWorkbook() is unnecessary. The collaboration service identifies the user and checks permissions with the authentication information carried in customHeaders, such as the Cookie. The server returns the memberID for the connection.

The example disables browser offline caching and the single-active-instance lock across tabs, so setCurrentUser() is not needed to isolate the cache of one account from another. If you later use features that depend on the local current user, such as comments, you can set the application user through UserManagerService. That setting does not replace server authentication.

The example keeps the collaboration connection open after it completes. Open the same document in a browser to observe the changes. flush() waits until the server acknowledges the queued collaboration changes. For a one-shot script, call univer.dispose() after all asynchronous operations and synchronization have finished.

How is this guide?

© 2026 DreamNum Co., Ltd.