Core Features

GitHubEdit on GitHub
Preset Info
@univerjs/preset-sheets-core
Server Required
No

Univer Sheets core features include a spreadsheet editor, formula engine, rendering engine, number formatting engine, design system, and UI component library. Together, they form a powerful platform for handling spreadsheets, supporting various formats and complex operations.

Features

Univer Sheets core features include:

  • Spreadsheet Rendering: Supports rendering of Univer Sheets, including cursor and selection drawing.
  • Cell Styling: Allows styling of cells in the spreadsheet, including font, color, borders, and alignment.
  • Formula Calculation: Supports adding and calculating formulas in the spreadsheet, covering nearly all Excel functions, including mathematical, statistical, text, and date functions.
  • Number Formatting: Enables formatting of numbers in the spreadsheet, including currency, percentage, date formats, etc.
  • Gridlines and Frozen Panes: Supports displaying gridlines and frozen panes, making it easier for users to view and edit large datasets.
  • Default Styles: Allows setting default styles for the spreadsheet, including default font, size, color, etc.
  • Plugin System: Supports a plugin system that allows for custom plugins, such as formula plugins, image plugins, chart plugins, etc. This is also one of the core architectural capabilities of Univer.

Preset Mode

Installation

npm install @univerjs/presets @univerjs/preset-sheets-core

Usage

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'

const { univerAPI } = createUniver({
  locale: LocaleType.En_US,
  locales: {
    [LocaleType.En_US]: mergeLocales(
      UniverPresetSheetsCoreEnUS,
    ),
  },
  presets: [
    UniverSheetsCorePreset(),
  ],
})

univerAPI.createWorkbook({})

Presets and Configuration

@univerjs/presets

This preset provides the createUniver method to create a Univer application, and exposes all methods and objects from @univerjs/core and @univerjs/design.

The createUniver method accepts a configuration object that includes options for theme, language, presets, etc. It returns a Univer instance univer and an FUniver instance univerAPI for calling the Facade API.

interface CreateUniverParameter {
  // Univer instance theme, default is `defaultTheme`
  theme: IStyleSheet
  // Whether to use dark mode, default is false
  darkMode?: boolean
  // The locale of the Univer instance
  locale: LocaleType
  // The locale objects to use, with keys as locale types and values as corresponding locale objects
  locales: ILocales
  // The log level of the Univer instance
  logLevel?: LogLevel
  // The list of presets to use.
  presets: IPresets[]
  // The list of plugins to use.
  plugins: IPlugins[]
}

Reference: createUniver

@univerjs/preset-sheets-core

This preset is the core preset of Univer Sheets, which includes the necessary core features for document editing, formula engine, rendering engine, etc.

interface IUniverSheetsCorePresetConfig {
  // Container element, can be a string or a DOM element
  container?: string | HTMLElement
  // Whether to show the header
  header?: boolean
  // Whether to show the header toolbar
  toolbar?: boolean
  // The type of the header toolbar. default: default compact mode; classic: classic mode; simple: ungrouped mode
  ribbonType?: RibbonType
  // Whether to show the footer
  footer?: false | {
    // Sheet bar is the sub-sheet manager, including adding/switching/deleting sub-sheets.
    sheetBar?: boolean
    // Statistic bar includes statistics of the current selection, such as count, sum, average, etc.
    statisticBar?: boolean
    // The bottom menu includes options like highlight, gridlines, etc.
    menus?: boolean
    // The zoom slider at the bottom.
    zoomSlider?: boolean
  }
  // Whether to show the context menu
  contextMenu?: boolean
  // Whether to disable auto focus
  disableAutoFocus?: true
  // Dependency injection override configuration
  override?: DependencyOverride
  // Menu configuration
  menu?: MenuConfig

  sheets?: {
    // If both row style and column style are set, whether row style precedes column style
    isRowStylePrecedeColumnStyle?: boolean
    // Whether auto height applies to merged cells
    autoHeightForMergedCells?: boolean
    /**
     * Whether synchronize the frozen state to other users in real-time collaboration.
     * @default true
     */
    freezeSync?: boolean

    clipboardConfig?: {
      // Whether to show the paste options button after paste operation
      hidePasteOptions?: boolean
    }
    // The configuration for the scroll bar
    scrollConfig?: IScrollBarProps
    /**
     * Strategy for showing the protected range shadow.
     * - true or 'always': Show shadow for all protected ranges (default behavior)
     * - 'non-editable': Only show shadow for ranges that cannot be edited (Edit permission is false)
     * - 'non-viewable': Only show shadow for ranges that cannot be viewed (View permission is false)
     * - false or 'none': Never show shadow for protected ranges
     * @default true
     */
    protectedRangeShadow?: boolean | 'always' | 'non-editable' | 'non-viewable' | 'none'
    // Whether to disable the force string alert.
    disableForceStringAlert?: boolean
    // Whether to disable the force string mark.
    disableForceStringMark?: boolean
  }

  // ... More configuration options
}

The menu configuration option can be used to simply set the display or hidden state of certain specific menu items:

UniverSheetsCorePreset({
  menu: {
    'sheet.command.set-range-bold': {
      hidden: true,
    },
    'sheet.command.set-range-italic': {
      hidden: true,
      disabled: true,
    },
  },
})

Here, 'sheet.command.set-range-bold' and 'sheet.command.set-range-italic' are the names of the commands, indicating the corresponding menu items. You can refer to the Menu Item ID List below.

Reference: @univerjs/preset-sheets-core

Plugin Mode

Installation

npm install @univerjs/core @univerjs/design @univerjs/engine-render @univerjs/engine-formula @univerjs/ui @univerjs/docs @univerjs/docs-ui @univerjs/sheets @univerjs/sheets-ui @univerjs/sheets-formula @univerjs/sheets-formula-ui @univerjs/sheets-numfmt @univerjs/sheets-numfmt-ui

Usage

import { LocaleType, mergeLocales, Univer } from '@univerjs/core'
import DesignEnUS from '@univerjs/design/locale/en-US'
import { UniverSheetsPlugin } from '@univerjs/docs'
import { UniverSheetsUIPlugin } from '@univerjs/docs-ui'
import SheetsUIEnUS from '@univerjs/docs-ui/locale/en-US'
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'
import { UniverRenderEnginePlugin } from '@univerjs/engine-render'
import { UniverSheetsPlugin } from '@univerjs/sheets'
import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula'
import { UniverSheetsFormulaUIPlugin } from '@univerjs/sheets-formula-ui'
import SheetsFormulaUIEnUS from '@univerjs/sheets-formula-ui/locale/en-US'
import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt'
import { UniverSheetsNumfmtUIPlugin } from '@univerjs/sheets-numfmt-ui'
import SheetsNumfmtUIEnUS from '@univerjs/sheets-numfmt-ui/locale/en-US'
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui'
import SheetsUIEnUS from '@univerjs/sheets-ui/locale/en-US'
import SheetsEnUS from '@univerjs/sheets/locale/en-US'
import { UniverUIPlugin } from '@univerjs/ui'
import UIEnUS from '@univerjs/ui/locale/en-US'

import '@univerjs/design/lib/index.css'
import '@univerjs/ui/lib/index.css'
import '@univerjs/docs-ui/lib/index.css'
import '@univerjs/sheets-ui/lib/index.css'
import '@univerjs/sheets-formula-ui/lib/index.css'
import '@univerjs/sheets-numfmt-ui/lib/index.css'

import '@univerjs/engine-formula/facade'
import '@univerjs/ui/facade'
import '@univerjs/docs-ui/facade'
import '@univerjs/sheets/facade'
import '@univerjs/sheets-ui/facade'
import '@univerjs/sheets-formula/facade'
import '@univerjs/sheets-numfmt/facade'

const univer = new Univer({
  locale: LocaleType.En_US,
  locales: {
    [LocaleType.En_US]: mergeLocales(
      DesignEnUS,
      UIEnUS,
      SheetsUIEnUS,
      SheetsEnUS,
      SheetsUIEnUS,
      SheetsFormulaUIEnUS,
      SheetsNumfmtUIEnUS,
    ),
  },
})

univer.registerPlugin(UniverRenderEnginePlugin)
univer.registerPlugin(UniverFormulaEnginePlugin)
univer.registerPlugin(UniverUIPlugin, {
  container: 'app',
})
univer.registerPlugin(UniverSheetsPlugin)
univer.registerPlugin(UniverSheetsUIPlugin)
univer.registerPlugin(UniverSheetsPlugin)
univer.registerPlugin(UniverSheetsUIPlugin)
univer.registerPlugin(UniverSheetsFormulaPlugin)
univer.registerPlugin(UniverSheetsFormulaUIPlugin)
univer.registerPlugin(UniverSheetsNumfmtPlugin)
univer.registerPlugin(UniverSheetsNumfmtUIPlugin)

Plugins and Configuration

@univerjs/core

This plugin is the core library of Univer, providing basic functionalities such as creating Univer instances, themes, and languages.

interface UniverParameter {
  // Univer instance theme, default is `defaultTheme`
  theme: IStyleSheet
  // Whether to use dark mode, default is false
  darkMode?: boolean
  // The locale of the Univer instance
  locale: LocaleType
  // The locale objects to use, with keys as locale types and values as corresponding locale objects
  locales: ILocales
  // The log level of the Univer instance
  logLevel?: LogLevel
}

Reference: Univer

@univerjs/engine-render

This plugin is the rendering engine of Univer, responsible for rendering, scrollbars, cursor, and selection rendering. It provides the UniverRenderEnginePlugin.

Reference: @univerjs/engine-render

@univerjs/engine-formula

This plugin is the formula engine of Univer, responsible for calculating and processing formulas. It provides the UniverFormulaEnginePlugin.

Reference: @univerjs/engine-formula

@univerjs/design

This plugin is the design system of Univer, providing all basic components and styles.

See: UI Chapter

@univerjs/ui

This plugin is the UI foundation of Univer. It provides the UniverUIPlugin.

The UniverUIPlugin provides some configuration options that can be used for basic layout configuration.

interface IUniverUIConfig {
  // Container element, can be a string or a DOM element
  container?: string | HTMLElement
  // Whether to show the header
  header?: boolean
  // Whether to show the header toolbar
  toolbar?: boolean
  // The type of the header toolbar. default: default compact mode; classic: classic mode; simple: ungrouped mode
  ribbonType?: RibbonType
  // Whether to show the context menu
  contextMenu?: boolean
  // Whether to disable auto focus
  disableAutoFocus?: true
  // Dependency injection override configuration
  override?: DependencyOverride
  // Menu configuration
  menu?: MenuConfig
}

The menu configuration option can be used to simply set the display or hidden state of certain specific menu items:

univer.registerPlugin(UniverSheetsUIPlugin, {
  menu: {
    'sheet.command.set-range-bold': {
      hidden: true,
    },
    'sheet.command.set-range-italic': {
      hidden: true,
      disabled: true,
    },
  },
})

Here, 'sheet.command.set-range-bold' and 'sheet.command.set-range-italic' are the names of the commands, indicating the corresponding menu items. You can refer to the Menu Item ID List below.

Reference: @univerjs/ui

@univerjs/docs

This plugin is the core plugin of Univer Docs. It provides the UniverDocsPlugin.

Reference: @univerjs/docs

@univerjs/docs-ui

This plugin is the UI plugin of Univer Docs, which includes UI components and interactions for the document editor. It provides the UniverDocsUIPlugin.

Reference: @univerjs/docs-ui

@univerjs/sheets

This plugin is the core plugin of Univer Sheets, providing the core functionalities of the spreadsheet editor. It provides the UniverSheetsPlugin.

The UniverSheetsPlugin provides some configuration options that can be used for the spreadsheet editor configuration.

interface IUniverSheetsConfig {
  // If both row style and column style are set, whether row style precedes column style
  isRowStylePrecedeColumnStyle?: boolean
  // Whether auto height applies to merged cells
  autoHeightForMergedCells?: boolean
  /**
   * Whether synchronize the frozen state to other users in real-time collaboration.
   * @default true
   */
  freezeSync?: boolean
}

Reference: @univerjs/sheets

@univerjs/sheets-ui

This plugin is the UI plugin of Univer Sheets, which includes UI components and interactions for the spreadsheet editor. It provides the UniverSheetsUIPlugin.

The UniverSheetsUIPlugin provides some configuration options that can be used for the spreadsheet editor UI configuration.

interface IUniverSheetsUIConfig {
  // Whether to show the footer.
  footer?: false | {
    // The sheet bar is the sub-sheet manager, including adding/switching/deleting sub-sheets.
    sheetBar?: boolean
    // The statistic bar includes statistics of the current selection, such as count, sum, average, etc.
    statisticBar?: boolean
    // The bottom menu includes options like highlight, gridlines, etc.
    menus?: boolean
    // The zoom slider at the bottom.
    zoomSlider?: boolean
  }
  // Whether to show the formula bar
  formulaBar?: boolean
  clipboardConfig?: {
    // Whether to show the paste options button after paste operation
    hidePasteOptions?: boolean
  }
  // The configuration for the scroll bar
  scrollConfig?: IScrollBarProps
  /**
   * Strategy for showing the protected range shadow.
   * - true or 'always': Show shadow for all protected ranges (default behavior)
   * - 'non-editable': Only show shadow for ranges that cannot be edited (Edit permission is false)
   * - 'non-viewable': Only show shadow for ranges that cannot be viewed (View permission is false)
   * - false or 'none': Never show shadow for protected ranges
   * @default true
   */
  protectedRangeShadow?: boolean | 'always' | 'non-editable' | 'non-viewable' | 'none'
  // Whether to disable the force string alert.
  disableForceStringAlert?: boolean
  // Whether to disable the force string mark.
  disableForceStringMark?: boolean
}

Reference: @univerjs/sheets-ui

Toolbar Layout and RibbonType

By configuring the ribbonType property in IUniverSheetsCorePresetConfig or IUniverUIConfig, you can set the layout of the toolbar.

ribbonType supports the following three modes:

  • default: Default compact mode, where groups and the toolbar are laid out in the same row, suitable for scenarios with limited vertical screen space.
  • classic: Classic mode, with groups on top and the toolbar laid out below, suitable for users accustomed to traditional layouts.
  • simple: Ungrouped mode, where all tools are placed in a flat list, suitable for users familiar with toolbar functions.

You can find the menu item ID through the data-u-command attribute on the menu item DOM element.

Toolbar Menu Items

Menu Item IDMenu Item Name
univer.command.undoUndo
univer.command.redoRedo
sheet.command.set-once-format-painterPaint format
sheet.command.set-range-boldBold
sheet.command.set-range-italicItalic
sheet.command.set-range-underlineUnderline
sheet.command.set-range-strokeStrikethrough
sheet.command.set-range-font-familyFont
sheet.command.set-range-fontsizeFont size
sheet.command.set-range-text-colorText color
sheet.command.set-background-colorFill color
sheet.command.set-border-basicBorder
sheet.command.set-horizontal-text-alignHorizontal align
sheet.command.set-vertical-text-alignVertical align
sheet.command.set-text-wrapText wrap
sheet.command.set-text-rotationText rotate
sheet.command.add-worksheet-mergeMerge cells
sheet.command.add-worksheet-merge-allMerge cells - Merge all
sheet.command.add-worksheet-merge-verticalMerge cells - Vertical merge
sheet.command.add-worksheet-merge-horizontalMerge cells - Horizontal merge
sheet.command.remove-worksheet-mergeMerge cells - Cancel merge
sheet.operation.open.conditional.formatting.panelConditional Formatting
formula-ui.operation.insert-functionFunctions
formula-ui.operation.more-functionsFunctions - More Functions
sheet.menu.sheets-sortSort
sheet.command.sort-range-ascSort - Ascending
sheet.command.sort-range-asc-extSort - Expand Ascending
sheet.command.sort-range-descSort - Descending
sheet.command.sort-range-desc-extSort - Expand Descending
sheet.command.sort-range-customSort - Custom Sort
sheet.menu.imageImage
sheet.command.insert-float-imageImage - Float Image
sheet.command.insert-cell-imageImage - Cell Image
sheet.command.numfmt.set.currencyCurrency
sheet.command.numfmt.add.decimal.commandIncrease decimal places
sheet.command.numfmt.subtract.decimal.commandDecreasing decimal places
sheet.command.numfmt.set.percentPercentage
sheet.operation.open.numfmt.panelNumber format
sheet.menu.data-validationData validation
data-validation.operation.open-validation-panelData validation - Data validation management
data-validation.command.addRuleAndOpenData validation - Add Rule
sheet.command.smart-toggle-filterToggle Filter
sheet.command.clear-filter-criteriaToggle Filter - Clear Filter Conditions
sheet.command.re-calc-filterToggle Filter - Re-calc Filter Conditions
sheet.operation.open-pivot-table-range-selector-panelPivot Table
sheet.menu.printPrint
sheet.operation.print-openPrint - Print
sheet.operation.open-print-grid-sidebarPrint - Print Layout
data-connector.operation.sidebarData Connector
sheets-exchange-client.operation.exchangeFile
exchange-client.operation.import-xlsxFile - Open(File)
exchange-client.operation.export-xlsxFile - Save As
sheet.command.menu-insert-chartInsert chart
sheet.command.add-range-protection-from-toolbarProtection
univer.operation.toggle-edit-historyEdit History
sheet.operation.open-sparkline-selectorSparkline
thread-comment-ui.operation.toggle-panelComment Management
sheet.operation.insert-hyper-link-toolbarInsert Link
ui.operation.open-find-dialogFind & Replace
base-ui.operation.toggle-shortcut-panelToggle Shortcut Panel

Context Menu Items

Menu Item IDMenu Item Name
sheet.command.copyCopy
sheet.command.pastePaste
sheet.menu.paste-specialPaste Special
sheet.command.paste-valuesPaste Special - Paste Value
sheet.command.paste-formatPaste Special - Paste Format
sheet.command.paste-col-widthPaste Special - Paste Column Width
sheet.command.paste-besides-borderPaste Special - Paste Besides Border Styles
sheet.command.paste-formulaPaste Special - Paste Formula
sheet.menu.clear-selectionClear
sheet.command.clear-selection-contentClear - Clear Contents
sheet.command.clear-selection-formatClear - Clear Formats
sheet.command.clear-selection-allClear - Clear All
sheet.menu.cell-insertInsert
sheet.command.insert-row-beforeInsert - Insert Row Before
sheet.command.insert-col-beforeInsert - Insert Column Before
sheet.command.insert-range-move-right-confirmInsert - Move Right
sheet.command.insert-range-move-down-confirmInsert - Move Down
sheet.menu.deleteDelete
sheet.command.remove-row-confirmDelete Selected Row
sheet.command.remove-col-confirmDelete Selected Column
sheet.command.delete-range-move-left-confirmDelete - Move Left
sheet.command.delete-range-move-up-confirmDelete - Move Up
sheet.menu.sheet-frozenFreeze
sheet.header-menu.sheet-frozenFreeze (Row & Column Header Right Click Menu Item)
sheet.command.set-selection-frozenFreeze - Freeze
sheet.command.set-row-frozenFreeze - Freeze to this row
sheet.command.set-col-frozenFreeze - Freeze to this column
sheet.command.cancel-frozenFreeze - Cancel freeze
sheet.contextMenu.permissionProtect Rows And Columns
sheet.command.add-range-protection-from-context-menuProtect Rows And Columns - Add Protection Range
sheet.command.set-range-protection-from-context-menuProtect Rows And Columns - Set Protection Range
sheet.command.delete-range-protection-from-context-menuProtect Rows And Columns - Remove Protection Range
sheet.command.view-sheet-permission-from-context-menuProtect Rows And Columns - View All Protection Ranges
sheet.menu.sheets-sort-ctxSort
sheet.command.sort-range-asc-ctxSort - Ascending
sheet.command.sort-range-asc-ext-ctxSort - Expand Ascending
sheet.command.sort-range-desc-ctxSort - Descending
sheet.command.sort-range-desc-ext-ctxSort - Expand Descending
sheet.command.sort-range-custom-ctxSort - Custom Sort
sheets.operation.show-comment-modalAdd Comment
sheet.operation.insert-hyper-linkInsert Link
zen-editor.command.open-zen-editorFull Screen Editor
sheet.operation.screenshotCopy as picture

Context Menu Items - Row Header

Menu Item IDMenu Item Name
sheet.command.insert-multi-rows-aboveInsert Row Before
sheet.command.insert-multi-rows-afterInsert Row After
sheet.command.hide-row-confirmHide Selected Row
sheet.command.set-selected-rows-visibleShow Hide Row
sheet.command.set-row-heightRow Height
sheet.command.set-row-is-auto-heightFit for data

Context Menu Items - Column Header

Menu Item IDMenu Item Name
sheet.command.insert-multi-cols-beforeInsert Column Before
sheet.command.insert-multi-cols-rightInsert Column After
sheet.command.hide-col-confirmHide Selected Column
sheet.command.set-selected-cols-visibleShow Hide Column
sheet.command.set-worksheet-col-widthColumn Width
sheet.command.set-col-auto-widthFit for data

How is this guide?