### Univer CDN Installation Example Source: https://docs.univer.ai/guides/docs/getting-started/installation/cdn Include Univer's UMD builds via script tags in your HTML for CDN installation. This example demonstrates setting up Univer with React, RxJS, ECharts, and the core preset, including locale configuration. ```html
``` -------------------------------- ### Install All Skills Source: https://docs.univer.ai/guides/skills/installation Use this command to install all available AI skills for Univer with a single command. This is the recommended approach for a complete setup. ```bash npx skills add dream-num/univer-sdk-skills ``` -------------------------------- ### Minimal Example (Plugin Mode) Source: https://docs.univer.ai/showcase/docs/slim-via-preset Demonstrates the minimum configuration required to use Univer Docs in plugin mode. This setup initializes Univer with core docs presets and creates a new document. ```typescript import { UniverDocsCorePreset } from '@univerjs/preset-docs-core' import docsCoreEnUS from '@univerjs/preset-docs-core/locales/en-US' import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets' import { DOCUMENT_DATA } from './data' import './styles.css' import '@univerjs/preset-docs-core/lib/index.css' const { univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( docsCoreEnUS, ), }, presets: [ UniverDocsCorePreset({ container: 'app', }), ], }) univerAPI.createUniverDoc(DOCUMENT_DATA) ``` -------------------------------- ### Start USIP Demo Service Source: https://docs.univer.ai/guides/pro/server Starts the USIP demo service after enabling it in the .env.custom file. ```bash bash run.sh start-demo-usip ``` -------------------------------- ### Install Web Component Adapter Source: https://docs.univer.ai/guides/docs/ui/components Install the necessary package for integrating Web Components with Univer. ```bash npm install @univerjs/ui-adapter-web-component ``` -------------------------------- ### Freeze Configuration Example Source: https://docs.univer.ai/guides/sheets/features/core/freeze Example of configuring freeze state with `xSplit`, `ySplit`, `startRow`, and `startColumn`. ```json { "xSplit": 1, // Freeze 1 column, which is column B "ySplit": 1, // Freeze 1 row, which is row 2 "startRow": 2, // The starting row that can be scrolled is row 3 "startColumn": 2 // The starting column that can be scrolled is column C } ``` -------------------------------- ### Manual Install: Clone Repository Source: https://docs.univer.ai/guides/skills/installation Manually install AI skills by cloning the repository. This method is useful for development or when automated installation is not feasible. ```bash git clone https://github.com/dream-num/univer-sdk-skills.git cd univer-sdk-skills ``` -------------------------------- ### Install Print Plugin Source: https://docs.univer.ai/guides/docs/features/print Install the Univer Docs Print plugin for standalone print functionality. ```bash npm install @univerjs-pro/docs-print ``` -------------------------------- ### Install Preset Dependencies Source: https://docs.univer.ai/guides/docs/features/print Install the necessary presets for advanced document features, including print functionality. ```bash npm install @univerjs/preset-docs-drawing @univerjs/preset-docs-advanced ``` -------------------------------- ### Install Callout Plugins Source: https://docs.univer.ai/guides/docs/features/callout Install the necessary callout plugins for Univer Docs using npm. ```bash npm install @univerjs-pro/docs-callout @univerjs-pro/docs-callout-ui ``` -------------------------------- ### Run Installation Script Source: https://docs.univer.ai/guides/pro/components Execute the installation script after creating the .env.custom file for Docker Compose deployments. ```bash run.sh ``` -------------------------------- ### Install @univerjs/sheets-sort and @univerjs/sheets-sort-ui Source: https://docs.univer.ai/guides/sheets/features/sort Install the plugin packages for sorting and its UI components. ```bash npm install @univerjs/sheets-sort @univerjs/sheets-sort-ui ``` -------------------------------- ### Install Enhanced List Plugins Source: https://docs.univer.ai/guides/docs/features/list Install the necessary plugins for the enhanced list feature using npm. Ensure you have Univer Pro installed. ```bash npm install @univerjs-pro/docs-list @univerjs-pro/docs-list-ui ``` -------------------------------- ### Install Preset Docs Drawing Source: https://docs.univer.ai/guides/docs/features/images Install the preset package for drawing features in Univer documents. ```bash npm install @univerjs/preset-docs-drawing ``` -------------------------------- ### Install Live Share Plugin Source: https://docs.univer.ai/guides/sheets/features/live-share Install the Live Share plugin using npm. This is the first step to enable collaborative features. ```bash npm install @univerjs-pro/live-share ``` -------------------------------- ### Install Quick Insert UI Plugin Source: https://docs.univer.ai/guides/docs/features/quick-insert Install the Quick Insert UI plugin using npm. This is the first step to enable the quick insert functionality. ```bash npm install @univerjs/docs-quick-insert-ui ``` -------------------------------- ### Install Quote Block Plugins Source: https://docs.univer.ai/guides/docs/features/quote Install the necessary quote block plugins for Univer Docs. ```bash npm install @univerjs-pro/docs-quote @univerjs-pro/docs-quote-ui ``` -------------------------------- ### Install Hyper Link Plugin Source: https://docs.univer.ai/guides/docs/features/hyper-link Install the core and UI packages for the Hyper Link plugin. ```bash npm install @univerjs/docs-hyper-link @univerjs/docs-hyper-link-ui ``` -------------------------------- ### Install @univerjs/preset-sheets-sort Source: https://docs.univer.ai/guides/sheets/features/sort Install the preset package for sorting functionality. ```bash npm install @univerjs/preset-sheets-sort ``` -------------------------------- ### Install Univer Server with Docker Compose Source: https://docs.univer.ai/guides/pro/server Installs the latest version of the Univer Server using a curl script. The script automatically installs Docker if it's not present. ```bash bash -c "$(curl -fsSL https://get.univer.ai)" ``` -------------------------------- ### Install Hyper Link Preset Source: https://docs.univer.ai/guides/docs/features/hyper-link Install the preset package for Hyper Link functionality. ```bash npm install @univerjs/preset-docs-hyper-link ``` -------------------------------- ### Install Pivot Table Plugin Packages Source: https://docs.univer.ai/guides/sheets/features/pivot-table Install the pivot table and pivot table UI plugins for Univer. ```bash npm install @univerjs-pro/sheets-pivot @univerjs-pro/sheets-pivot-ui ``` -------------------------------- ### Install and Register WebSocket Plugin Source: https://docs.univer.ai/guides/docs/features/core/general-api Demonstrates the necessary imports and plugin registration for using the WebSocket functionality with piecemeal installation. ```typescript // ... Omits other plugin imports import { UniverNetworkPlugin } from '@univerjs/network' // ... Omits other facade imports import '@univerjs/network/facade' // ... Omits other plugin registrations univer.registerPlugin(UniverNetworkPlugin) ``` -------------------------------- ### Install Univer Observability Components Source: https://docs.univer.ai/guides/pro/deploy/kubernetes Install Univer's configured observability components using Helm. Ensure the `global.univerNamespace` is set correctly. ```bash helm upgrade --install -n univer-observability --create-namespace \ --set global.univerNamespace="univer" \ univer-observability \ oci://univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/helm-charts/univer-observability ``` -------------------------------- ### Install Preset Mode Source: https://docs.univer.ai/guides/sheets/features/conditional-formatting Install the conditional formatting preset package for Univer Sheets. ```bash npm install @univerjs/preset-sheets-conditional-formatting ``` -------------------------------- ### Install Univer Icons Source: https://docs.univer.ai/icons Install the official Univer icon package using npm. ```bash npm install @univerjs/icons ``` -------------------------------- ### Install Collaboration Plugins Source: https://docs.univer.ai/guides/docs/features/collaboration Install the necessary packages for the Univer Pro collaboration plugin mode. This includes the core collaboration package, the client, and the UI client. ```bash npm install @univerjs-pro/collaboration @univerjs-pro/collaboration-client @univerjs-pro/collaboration-client-ui ``` -------------------------------- ### Install Shape Plugins Source: https://docs.univer.ai/guides/docs/features/shape Install the necessary shape and shape UI plugins for Univer Docs using npm. ```bash npm install @univerjs-pro/docs-shape @univerjs-pro/docs-shape-ui ``` -------------------------------- ### Install Zen Editor Plugin Source: https://docs.univer.ai/guides/sheets/features/zen Install the Zen Editor plugin using npm. This is the first step for both Preset and Plugin modes. ```bash npm install @univerjs/sheets-zen-editor ``` -------------------------------- ### Install Univer Docs Core Preset Source: https://docs.univer.ai/guides/docs/features/core Install the necessary packages for Univer Docs core features using npm, pnpm, yarn, or bun. ```bash npm install @univerjs/presets @univerjs/preset-docs-core ``` -------------------------------- ### Install Advanced Formula Engine Preset Source: https://docs.univer.ai/guides/sheets/features/advanced-formula Install the necessary presets for the advanced formula engine, including drawing and advanced presets. Ensure the drawing preset is installed first as it's a runtime dependency. ```bash npm install @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advanced ``` -------------------------------- ### Install Collaboration Presets Source: https://docs.univer.ai/guides/docs/features/collaboration Install the necessary presets for collaborative editing in Univer Docs. This includes drawing, advanced, and collaboration presets. ```bash npm install @univerjs/preset-docs-drawing @univerjs/preset-docs-advanced @univerjs/preset-docs-collaboration ``` -------------------------------- ### Install Data Validation Preset Source: https://docs.univer.ai/guides/sheets/features/data-validation Install the preset package for data validation using npm. ```bash npm install @univerjs/preset-sheets-data-validation ``` -------------------------------- ### Install Data Validation Plugins Source: https://docs.univer.ai/guides/sheets/features/data-validation Install the core, sheets, and UI plugins for data validation in plugin mode. ```bash npm install @univerjs/data-validation @univerjs/sheets-data-validation @univerjs/sheets-data-validation-ui ``` -------------------------------- ### Install Uniscript via npm Source: https://docs.univer.ai/guides/docs/features/uniscript Install the Uniscript package using npm. This is the first step for both Preset and Plugin modes. ```bash npm install @univerjs/uniscript ``` -------------------------------- ### Install Plugin Mode Packages Source: https://docs.univer.ai/guides/docs/features/images Install the necessary packages for using Univer in plugin mode with drawing and docs drawing features. ```bash npm install @univerjs/drawing @univerjs/drawing-ui @univerjs/docs-drawing @univerjs/docs-drawing-ui ``` -------------------------------- ### Install Skills Globally Source: https://docs.univer.ai/guides/skills/installation Install AI skills for Univer globally, making them accessible across all your projects. Use this for skills you frequently use. ```bash npx skills add dream-num/univer-sdk-skills --global ``` -------------------------------- ### Install and Run Univer Doc Starter Kit with npm Source: https://docs.univer.ai/guides/docs/getting-started/quickstart Use this command to set up a local Univer document project using npm. Ensure Node.js, npm, and Git are installed. ```bash npx degit dream-num/univer-doc-start-kit univer-doc-start-kit cd univer-doc-start-kit npm install npm run dev ``` -------------------------------- ### Install Univer Exchange Client Plugins Source: https://docs.univer.ai/guides/docs/features/import-export Install the necessary client-side plugins for Univer's exchange functionality, used in plugin mode. ```bash npm install @univerjs-pro/exchange-client @univerjs-pro/docs-exchange-client ``` -------------------------------- ### Install Plugin Mode Source: https://docs.univer.ai/guides/sheets/features/conditional-formatting Install the conditional formatting and UI packages for Univer Sheets plugin mode. ```bash npm install @univerjs/sheets-conditional-formatting @univerjs/sheets-conditional-formatting-ui ``` -------------------------------- ### Install Code Block Plugins Source: https://docs.univer.ai/guides/docs/features/code Install the necessary plugins for the code block feature using npm. ```bash npm install @univerjs-pro/docs-code @univerjs-pro/docs-code-ui ``` -------------------------------- ### Install and Run Univer Doc Starter Kit with pnpm Source: https://docs.univer.ai/guides/docs/getting-started/quickstart Use this command to set up a local Univer document project using pnpm. Ensure Node.js, pnpm, and Git are installed. ```bash pnpm dlx degit dream-num/univer-doc-start-kit univer-doc-start-kit cd univer-doc-start-kit pnpm install pnpm dev ``` -------------------------------- ### Install Advanced Formula Engine Plugin Source: https://docs.univer.ai/guides/sheets/features/advanced-formula Install the Univer Pro formula engine package for plugin-based integration. ```bash npm install @univerjs-pro/engine-formula ``` -------------------------------- ### Install Crosshair Highlight Plugin (npm) Source: https://docs.univer.ai/guides/sheets/features/crosshair-highlighting Install the crosshair highlighting plugin using npm. This is the first step for both preset and plugin modes. ```bash npm install @univerjs/sheets-crosshair-highlight ``` -------------------------------- ### Install Univer Pro Sheet Starter Kit with npm Source: https://docs.univer.ai/guides/pro Use this command to set up the Univer Pro sheet starter kit using npm. Ensure Node.js and npm are installed. ```bash npx degit dream-num/univer-pro-sheet-start-kit univer-pro-sheet-start-kit cd univer-pro-sheet-start-kit npm install npm run dev ``` -------------------------------- ### getRow Source: https://docs.univer.ai/reference/facade/range Gets the starting row index of the range. Indices are 0-based. ```APIDOC ## getRow ### Description Gets the starting row index of the range. index starts at 0. ### Method ``` getRow(): number ``` ### Returns #### Success Response - **number** - The starting row index of the range. ### Examples ```javascript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:B2'); console.log(fRange.getRow()); // 0 ``` ``` -------------------------------- ### getColumn Source: https://docs.univer.ai/reference/facade/range Gets the starting column index of the range. Indices are 0-based. ```APIDOC ## getColumn ### Description Gets the starting column index of the range. index starts at 0. ### Method ``` getColumn(): number ``` ### Returns #### Success Response - **number** - The starting column index of the range. ### Examples ```javascript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:B2'); console.log(fRange.getColumn()); // 0 ``` ``` -------------------------------- ### Install Univer Pro Sheet Starter Kit with pnpm Source: https://docs.univer.ai/guides/pro Use this command to set up the Univer Pro sheet starter kit using pnpm. Ensure Node.js and pnpm are installed. ```bash pnpm dlx degit dream-num/univer-pro-sheet-start-kit univer-pro-sheet-start-kit cd univer-pro-sheet-start-kit pnpm install pnpm dev ``` -------------------------------- ### Get Connector Start Connection Info Source: https://docs.univer.ai/reference/facade/shape Retrieves connection details for a connector shape's start point. Use this to find out which shape and connection site a connector is attached to. ```typescript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const shapes = fWorksheet.getShapes(); const connector = shapes.find((s) => s.isLineShape()); if (connector) { const startInfo = connector.getStartConnectInfo(); if (startInfo) { console.log(`Start connected to shape ${startInfo.shapeId} at site ${startInfo.cxnIndex}`); } } ``` -------------------------------- ### Install Vue 3 Adapter Plugin Source: https://docs.univer.ai/guides/docs/ui/components Install the necessary UI adapter plugin for Vue 3.x components. ```bash npm install @univerjs/ui-adapter-vue3 ``` -------------------------------- ### Install Specific Skill Source: https://docs.univer.ai/guides/skills/installation Install a particular AI skill for Univer by specifying its name. Useful when you only need a subset of the available skills. ```bash npx skills add dream-num/univer-sdk-skills --skill univer-integrate ``` ```bash npx skills add dream-num/univer-sdk-skills --skill univer-plugin-dev ``` ```bash npx skills add dream-num/univer-sdk-skills --skill univer-pro-integrate ``` ```bash npx skills add dream-num/univer-sdk-skills --skill univer-node-backend ``` -------------------------------- ### Get A1 Notation for a Range Source: https://docs.univer.ai/reference/facade/range Demonstrates how to get the A1 notation of a range with options to include the sheet name and specify absolute reference types for start and end cells. ```typescript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); // By default, the A1 notation is returned without the sheet name and without absolute reference types. const fRange = fWorksheet.getRange('A1:B2'); console.log(fRange.getA1Notation()); // A1:B2 // By setting withSheet to true, the sheet name is included in the A1 notation. fWorksheet.setName('Sheet1'); console.log(fRange.getA1Notation(true)); // Sheet1!A1:B2 // By setting startAbsoluteRefType, the absolute reference type for the start cell is included in the A1 notation. console.log(fRange.getA1Notation(false, univerAPI.Enum.AbsoluteRefType.ROW)); // A$1:B2 console.log(fRange.getA1Notation(false, univerAPI.Enum.AbsoluteRefType.COLUMN)); // $A1:B2 console.log(fRange.getA1Notation(false, univerAPI.Enum.AbsoluteRefType.ALL)); // $A$1:B2 // By setting endAbsoluteRefType, the absolute reference type for the end cell is included in the A1 notation. console.log(fRange.getA1Notation(false, null, univerAPI.Enum.AbsoluteRefType.ROW)); // A1:B$2 console.log(fRange.getA1Notation(false, null, univerAPI.Enum.AbsoluteRefType.COLUMN)); // A1:$B2 console.log(fRange.getA1Notation(false, null, univerAPI.Enum.AbsoluteRefType.ALL)); // A1:$B$2 // By setting all parameters example console.log(fRange.getA1Notation(true, univerAPI.Enum.AbsoluteRefType.ALL, univerAPI.Enum.AbsoluteRefType.ALL)); // Sheet1!$A$1:$B$2 ``` -------------------------------- ### Get Table Info by Cell using Facade API Source: https://docs.univer.ai/guides/sheets/features/table Retrieve table information associated with a specific cell using `getTableByCell`. This example shows how to get table info for cell B2 before and after inserting a table. ```typescript const fWorkbook = univerAPI.getActiveWorkbook() const fWorksheet = fWorkbook.getActiveSheet() const cellB2 = fWorksheet.getRange('B2') const row = cellB2.getRow() const column = cellB2.getColumn() console.log('debugger tableInfo', fWorksheet.getTableByCell(row, column)) // Insert a table in the range B2:F11 const fRange = fWorksheet.getRange('B2:F11') const success = await fWorksheet.addTable( 'name-1', fRange.getRange(), 'id-1', { tableStyleId: 'table-default-4', }, ) console.log('debugger tableInfo2', fWorksheet.getTableByCell(row, column)) ``` -------------------------------- ### Install Univer Sheets Core Preset Source: https://docs.univer.ai/guides/sheets/features/core Install the necessary packages for Univer Sheets core functionality using npm. ```bash npm install @univerjs/presets @univerjs/preset-sheets-core ``` -------------------------------- ### Get Starting Row Index of a Range Source: https://docs.univer.ai/reference/facade/range Returns the zero-based index of the first row in the range. Useful for row-based operations. ```typescript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:B2'); console.log(fRange.getRow()); // 0 ``` -------------------------------- ### Comprehensive .env.custom Configuration Example Source: https://docs.univer.ai/guides/pro/deploy/docker-compose An example .env.custom file demonstrating advanced configurations for USIP integration, permission control, event synchronization, self-hosted PostgreSQL and S3, custom ports, and service scaling. ```shell # 1. enable USIP integration # usip about USIP_ENABLED=true USIP_URI_CREDENTIAL=https://usip-demo.univer.ai/usip/credential USIP_URI_USERINFO=https://usip-demo.univer.ai/usip/userinfo USIP_URI_ROLE=https://usip-demo.univer.ai/usip/role USIP_URI_COLLABORATORS=https://usip-demo.univer.ai/usip/collaborators USIP_URI_UNITEDITTIME=https://usip-demo.univer.ai/usip/unit-edit-time # 2. only owner can copy content and print AUTH_PERMISSION_CUSTOMER_STRATEGIES=[ {"action": 3, "role": 2}, {"action": 6, "role": 2} ] # 3. enable univer event sync EVENT_SYNC=true # Set to true to enable # 4. use owner RDS # postgresql config DISABLE_UNIVER_RDS=true # When using your own RDS, disable Univer's default PostgreSQL DATABASE_DRIVER=postgresql # Set to postgresql for PostgreSQL-compatible databases DATABASE_HOST=univer-postgresql DATABASE_PORT=5432 DATABASE_DBNAME=univer DATABASE_USERNAME=universer-biz DATABASE_PASSWORD=123456 # 5. use owner Object storage # s3 config DISABLE_UNIVER_S3=true # When using your own object storage, disable Univer's built-in MinIO S3_USER=universer-biz S3_PASSWORD=123456 S3_REGION=cn-sz S3_PATH_STYLE=true S3_ENDPOINT=univer-s3:9652 S3_ENDPOINT_PUBLIC=univer.ai:9653 S3_DEFAULT_BUCKET=univer # 6. change univer service Port HOST_NGINX_PORT=8010 # 7. set the service scale UNIVERSER_REPLICATION_CNT=4 # universer instance count COLLABORATION_SERVER_REPLICATION_CNT=5 # collaboration service instance count MAX_MEMORY_LIMIT=2048 # collaboration service max memory limit, in MB ``` -------------------------------- ### Get Starting Column Index of a Range Source: https://docs.univer.ai/reference/facade/range Returns the zero-based index of the first column in the range. Useful for column-based operations. ```typescript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:B2'); console.log(fRange.getColumn()); // 0 ``` -------------------------------- ### Get Row Outline Groups Source: https://docs.univer.ai/reference/facade/worksheet Retrieves all row outline groups from the current worksheet. Logs the ID, start, end, and collapsed state of each outline. ```typescript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const rowOutlines = fWorksheet.getDimensionOutlines(univerAPI.Enum.DimensionOutlineAxis.ROW); rowOutlines.forEach((outline) => { console.log(outline.id, outline.start, outline.end, outline.collapsed); }); ``` -------------------------------- ### Get Custom Meta Data Source: https://docs.univer.ai/reference/facade/range Returns the custom meta data associated with the cell at the start of the specified range. This is useful for storing and retrieving arbitrary data linked to a cell. ```typescript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:B2'); console.log(fRange.getCustomMetaData()); ``` -------------------------------- ### Get Freeze State using FWorksheet Source: https://docs.univer.ai/guides/sheets/features/core/freeze Retrieves the current freeze state of the worksheet, including frozen columns, rows, and scrollable starting points, using the `getFreeze` method. ```javascript const worksheet = univerAPI.getActiveWorkbook().getActiveSheet() const freezeState = worksheet.getFreeze() ``` -------------------------------- ### Start Univer Server Source: https://docs.univer.ai/guides/pro/troubleshooting Initiates the Univer server startup process using a local script. Useful for debugging demo UI accessibility. ```bash cd univer-server && bash run.sh start ``` -------------------------------- ### Get Used Theme Style of a Range Source: https://docs.univer.ai/reference/facade/range Retrieves the name of the theme style applied to a range. If no theme style is applied, it returns undefined. The example also shows how to apply a theme style. ```typescript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:E20'); console.log(fRange.getUsedThemeStyle()); // undefined fRange.useThemeStyle('default'); console.log(fRange.getUsedThemeStyle()); // 'default' ``` -------------------------------- ### Importing the Facade API Source: https://docs.univer.ai/guides/docs/features/core/general-api Demonstrates how to import and initialize the Univer Facade API. ```APIDOC ## Importing the Facade API ``` import { FUniver } from '@univerjs/core/facade' const univerAPI = FUniver.newAPI(univer) ``` ``` -------------------------------- ### Node.js Headless Univer Docs Setup Source: https://docs.univer.ai/showcase/docs/node-via-plugin This snippet shows the essential imports and setup for running Univer Docs in a Node.js environment. It includes registering necessary plugins like render, formula, and docs, and creating a new document instance with provided data. ```typescript import type { DocumentDataModel } from '@univerjs/core' import { IUniverInstanceService, LocaleType, Univer, UniverInstanceType } from '@univerjs/core' import { UniverDocsPlugin } from '@univerjs/docs' import { UniverFormulaEnginePlugin } from '@univerjs/formula-engine' import { UniverRenderEnginePlugin } from '@univerjs/engine-render' import { DOCUMENT_DATA } from '../code/data' const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: {}, }, }) univer.registerPlugin(UniverRenderEnginePlugin) univer.registerPlugin(UniverFormulaEnginePlugin) univer.registerPlugin(UniverDocsPlugin) univer.createUnit(UniverInstanceType.UNIVER_DOC, DOCUMENT_DATA) const injector = univer.__getInjector() const univerInstanceService = injector.get(IUniverInstanceService) const units = univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_DOC) const snapshots = units.map(unit => unit.getSnapshot()) // eslint-disable-next-line no-console console.log(JSON.stringify(snapshots, null, 2)) ``` -------------------------------- ### Get Raw Value of Top-Left Cell in Range Source: https://docs.univer.ai/reference/facade/range Retrieves the raw value of the top-left cell in a range. Returns null for empty cells. This example also demonstrates setting a value with a percentage format. ```javascript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:B2'); fRange.setValueForCell({ v: 0.2, s: { n: { pattern: '0%', }, }, }); console.log(fRange.getRawValue()); // 0.2 ``` -------------------------------- ### Live Share Facade API Source: https://docs.univer.ai/guides/sheets/features/live-share The Live Share feature extends relevant interfaces in the Facade API, which can be called directly through univerAPI. This includes functions to get the current status and to start or stop presenting or following. ```APIDOC ## Live Share Facade API ### Description Provides methods to control and query the status of the Live Share feature, enabling real-time view synchronization for collaborative editing. ### Usage These methods are available via the `univerAPI` object after importing the Live Share facade. ### Methods #### `getLiveShareStatus()` - **Description**: Retrieves the current status of the Live Share feature. - **Returns**: `LiveShareStatus` - The current status (IDLE, FOLLOWING, PRESENTING). #### `startPresenting()` - **Description**: Starts the Live Share presenting mode, allowing others to follow your view. - **Usage**: Call when `getLiveShareStatus()` returns `LiveShareStatus.IDLE`. #### `stopPresenting()` - **Description**: Stops the Live Share presenting mode. - **Usage**: Call when `getLiveShareStatus()` returns `LiveShareStatus.PRESENTING`. #### `startFollowing()` - **Description**: Starts the Live Share following mode, allowing you to follow another user's view. #### `stopFollowing()` - **Description**: Stops the Live Share following mode. ### Status Enum ```typescript export enum LiveShareStatus { IDLE = 'idle', FOLLOWING = 'following', PRESENTING = 'presenting', } ``` ### Example Usage ```typescript // Get current status const status = univerAPI.getLiveShareStatus() if (status === LiveShareStatus.IDLE) { // If currently idle, start presenting univerAPI.startPresenting() } else if (status === LiveShareStatus.PRESENTING) { // If presenting, stop presenting univerAPI.stopPresenting() } // Start following univerAPI.startFollowing() // Stop following univerAPI.stopFollowing() ``` ``` -------------------------------- ### Add and Get Sparkline Group Instance Source: https://docs.univer.ai/guides/sheets/features/sparkline Shows how to add multiple sparklines and then compose them into a sparkline group. This allows for managing related sparklines together. The example includes a timeout to demonstrate composing the group after a delay. ```javascript const fWorkbook = univerAPI.getActiveWorkbook() const fWorksheet = fWorkbook.getActiveSheet() // Create a sparkline with data source from A1:A7, placed in cell A10. const firstSparkline = fWorksheet.addSparkline( [fWorksheet.getRange('A1:A7').getRangeフィック], [fWorksheet.getRange('A10').getRangeフィック], ) // Create a sparkline with data source from B1:B7, placed in cell B10. const secondSparkline = fWorksheet.addSparkline( [fWorksheet.getRange('B1:B7').getRangeフィック], [fWorksheet.getRange('B10').getRangeフィック], ) console.log('Cell A10: ', fWorksheet.getSparklineGroupByCell(9, 0)) // After 3 seconds, compose the two sparklines into a sparkline group setTimeout(() => { fWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRangeフィック]) console.log('Cell A10: ', fWorksheet.getSparklineGroupByCell(9, 0)) }, 3000) ``` -------------------------------- ### Initialize Univer Instance and Register Plugins Source: https://docs.univer.ai/guides/docs/features/core Usage example demonstrating how to initialize a Univer instance, merge locales, and register core plugins for document editing. ```typescript import { LocaleType, mergeLocales, Univer } from '@univerjs/core' import DesignEnUS from '@univerjs/design/locale/en-US' import { UniverDocsPlugin } from '@univerjs/docs' import { UniverDocsUIPlugin } from '@univerjs/docs-ui' import DocsUIEnUS from '@univerjs/docs-ui/lib/locale/en-US' import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula' import { UniverRenderEnginePlugin } from '@univerjs/engine-render' import { UniverUIPlugin } from '@univerjs/ui' import UIEnUS from '@univerjs/ui/locale/en-US' import '@univerjs/docs-ui/facade' import '@univerjs/design/lib/index.css' import '@univerjs/ui/lib/index.css' import '@univerjs/docs-ui/lib/index.css' const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( DesignEnUS, UIEnUS, DocsUIEnUS, ), }, }) univer.registerPlugin(UniverRenderEnginePlugin) univer.registerPlugin(UniverFormulaEnginePlugin) univer.registerPlugin(UniverUIPlugin, { container: 'app', }) univer.registerPlugin(UniverDocsPlugin) univer.registerPlugin(UniverDocsUIPlugin) univer.createUnit(UniverInstanceType.UNIVER_DOC, {}) ``` -------------------------------- ### Control Live Share Presentation and Following Source: https://docs.univer.ai/guides/sheets/features/live-share Use the univerAPI to get the current Live Share status and control presentation or following modes. This allows users to start or stop presenting, or to follow another user's view. ```typescript // Get current status const status = univerAPI.getLiveShareStatus() if (status === LiveShareStatus.IDLE) { // If currently idle, start presenting univerAPI.startPresenting() } else if (status === LiveShareStatus.PRESENTING) { // If presenting, stop presenting univerAPI.stopPresenting() } // Start following univerAPI.startFollowing() // Stop following univerAPI.stopFollowing() ``` -------------------------------- ### Get Raw Values for Cells in Range Source: https://docs.univer.ai/reference/facade/range Retrieves raw values for all cells within a range as a 2D array. Empty cells are represented by null. This example also shows setting multiple values with different number formats. ```javascript const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:B2'); fRange.setValues([ [ { v: 0.2, s: { n: { pattern: '0%', }, }, }, { v: 45658, s: { n: { pattern: 'yyyy-mm-dd', }, }, } ], [ { v: 1234.567, s: { n: { pattern: '#,##0.00', } } }, null, ], ]); console.log(fRange.getRawValues()); // [[0.2, 45658], [1234.567, null]] ``` -------------------------------- ### Start New Services (Docker Compose) Source: https://docs.univer.ai/guides/pro/downtime-upgrade Start the newly deployed Univer Pro services using the `run.sh` script. This command is executed after the new version has been deployed and configured. ```bash bash run.sh start ``` -------------------------------- ### Main Thread Worker Setup Source: https://docs.univer.ai/guides/sheets/features/core/worker Configure the main thread to use a Web Worker for formula calculations by specifying the `workerURL` in the `UniverSheetsCorePreset`. This example also imports necessary presets and locales for core Sheets functionality and filter-related calculations. ```typescript import { UniverSheetsCorePreset } from '@univerjs/preset-sheets-core' import UniverPresetSheetsCoreEnUS from '@univerjs/preset-sheets-core/locales/en-US' import { UniverSheetsFilterPreset } from '@univerjs/preset-sheets-filter' import UniverPresetSheetsFilterEnUS from '@univerjs/preset-sheets-filter/locales/en-US' import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets' import '@univerjs/preset-sheets-core/lib/index.css' import '@univerjs/preset-sheets-filter/lib/index.css' const { univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( UniverPresetSheetsCoreEnUS, UniverPresetSheetsFilterEnUS, ), }, presets: [ UniverSheetsCorePreset({ workerURL: new Worker(new URL('./worker.js', import.meta.url), { type: 'module' }), }), UniverSheetsFilterPreset(), ], }) univerAPI.createWorkbook({ name: 'Test Sheet' }) ``` -------------------------------- ### Initialize Univer Instance with Plugins Source: https://docs.univer.ai/guides/sheets/features/core Demonstrates how to initialize the Univer instance and register various core plugins, including rendering, formula engine, UI, and sheets-specific plugins. It also shows how to configure locales. ```typescript 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) ``` -------------------------------- ### Install Univer Core and Related Plugins Source: https://docs.univer.ai/guides/docs/features/core Command to install the necessary packages for Univer core, rendering engine, formula engine, design system, UI, and docs. ```bash npm install @univerjs/core @univerjs/engine-render @univerjs/engine-formula @univerjs/design @univerjs/ui @univerjs/docs @univerjs/docs-ui ``` -------------------------------- ### Get Pivot Table Range Information Source: https://docs.univer.ai/reference/facade/pivot-table Retrieves the range information for a pivot table, including its start and end cells. This is useful for operations that require knowledge of the pivot table's location on the sheet. Check if the pivot table exists before accessing its range. ```typescript const fWorkbook = univerAPI.getActiveWorkbook(); const unitId = fWorkbook.getId(); const fSheet = fWorkbook.getActiveSheet(); const subUnitId = fSheet.getSheetId(); // Here we assume that you already have a pivot table in cell A8 of the table. // If not, please call fWorkbook.addPivotTable() according to the documentation. const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8); if(fPivotTable) { const pivotTableRangeInfo = fPivotTable.getPivotTableRangeInfo(); console.log(pivotTableRangeInfo); } ``` -------------------------------- ### get Source: https://docs.univer.ai/reference/facade/network Send a GET request to the server. This method is part of the Network facade for making HTTP GET requests. ```APIDOC ## get ### Description Send a GET request to the server. ### Method GET ### Endpoint ``` get(url: string, params?: IRequestParams): Promise> ``` ### Parameters #### Path Parameters - **url** (string) - Required - The URL to send the GET request to. - **params** (IRequestParams) - Optional - Additional parameters for the request. ### Response #### Success Response - **HTTPResponse** - Network response. ``` -------------------------------- ### Initialize Univer with Print Plugin Source: https://docs.univer.ai/guides/docs/features/print Set up Univer and register the print plugin, including locale configuration for the plugin. ```typescript import { UniverDocsPrintPlugin } from '@univerjs-pro/docs-print' import DocsPrintPluginEnUS from '@univerjs-pro/docs-print/locale/en-US' import { LocaleType, mergeLocales, Univer } from '@univerjs/core' import '@univerjs-pro/docs-print/lib/index.css' const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( DocsPrintPluginEnUS, ), }, }) univer.registerPlugin(UniverDocsPrintPlugin) ``` -------------------------------- ### Install Edit History Presets Source: https://docs.univer.ai/guides/sheets/features/edit-history Install the necessary presets for edit history functionality in Univer Sheets. Ensure `@univerjs/preset-sheets-drawing` is installed first as it's a runtime dependency. ```bash npm install @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advanced @univerjs/preset-sheets-collaboration ``` -------------------------------- ### Initialize Univer with Plugins via CDN Source: https://docs.univer.ai/guides/docs/getting-started/installation/cdn Initialize the Univer instance, register core plugins like rendering, formula, UI, and docs, and create a Univer instance for document editing. ```javascript const { Univer, LocaleType, mergeLocales, UniverInstanceType } = UniverCore const { FUniver } = UniverCoreFacade const { UniverRenderEnginePlugin } = UniverEngineRender const { UniverFormulaEnginePlugin } = UniverEngineFormula const { UniverUIPlugin } = UniverUi const { UniverDocsPlugin } = UniverDocs const { UniverDocsUIPlugin } = UniverDocsUi const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales(UniverDesignEnUS, UniverUiEnUS, UniverDocsUiEnUS), }, }) univer.registerPlugin(UniverRenderEnginePlugin) univer.registerPlugin(UniverFormulaEnginePlugin) univer.registerPlugin(UniverUIPlugin, { container: 'app', }) univer.registerPlugin(UniverDocsPlugin) univer.registerPlugin(UniverDocsUIPlugin) univer.createUnit(UniverInstanceType.UNIVER_DOC, {}) const univerAPI = FUniver.newAPI(univer) ``` -------------------------------- ### Install Univer Sheets Core Preset Dependencies Source: https://docs.univer.ai/guides/sheets/features/core Installs the necessary packages for the Univer Sheets core preset using npm. Ensure all listed dependencies are installed for full functionality. ```bash 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 ``` -------------------------------- ### Formula Calculation Start Event Source: https://docs.univer.ai/guides/sheets/features/core/formula Listens for the formula calculation start event. ```APIDOC ## Formula Calculation Start Event ### Description Listens for the formula calculation start event. ### Method ```javascript const formulaEngine = univerAPI.getFormula() formulaEngine.calculationStart((forceCalculate) => { console.log(forceCalculate) }) ``` ``` -------------------------------- ### Univer Instance Initialization Source: https://docs.univer.ai/reference/packages/plugins/univerjs/core Demonstrates how to create a new Univer instance with a given configuration. The Univer instance serves as the main entry point for interacting with the Univer application. ```APIDOC ## Initialize Univer Instance ### Description Creates a new Univer instance, which is the main entry point for the Univer application. It accepts an optional configuration object to customize its behavior. ### Method ```javascript new Univer(config?: IUniverConfig) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { Univer } from '@univerjs/core' const univer = new Univer(IUniverConfig) ``` ### Response #### Success Response An instance of the `Univer` class. #### Response Example ```json { "instance": "Univer" } ``` ``` -------------------------------- ### Vue 2.x Univer Integration Example Source: https://docs.univer.ai/guides/docs/getting-started/integrations/vue Demonstrates how to initialize and clean up Univer in a Vue 2.x application using `mounted` and `beforeUnmount` hooks. ```vue ``` -------------------------------- ### Initialize Univer Instance Source: https://docs.univer.ai/reference/packages/plugins/univerjs/core Demonstrates how to import and initialize a Univer instance with basic configuration. ```typescript import { Univer } from '@univerjs/core' const univer = new Univer(IUniverConfig) ``` -------------------------------- ### Start Presenting Live Share Session Source: https://docs.univer.ai/reference/facade/univer Initiates the presenting mode in a live-sharing session. This function has no parameters and returns void. ```typescript startPresenting(): void ```