Skip to Content
🎉 Univer 0.5.5 is released.Read more →

Script

Client Script

How to Create

In the Workspace, click the + button, and select the Client script type to create a Client script.

Client Script

How to Edit

Click the Client script to enter the editor. The editor supports JavaScript syntax highlighting, code suggestions, and other features.

Client Editor

univerAPI

In the Client script, you can directly use the univerAPI object, which provides some common APIs, such as:

function onOpen(){ const workbook = univerAPI.getActiveWorkbook(); const sheet = workbook.getActiveSheet(); }

For more API details, please refer to the Univer Sheets API.

runOnServer

In the Client script, you can use the runOnServer method to call methods in the Server script and get the return values, for example:

async function getServerData(){ const answerData = await univerAPI.runOnServer('ai', 'gpt', `Extract subject from "What is the capital of China?"`); Logger.log('answer:', answerData); }

The first parameter is the Server script name, the second is the method name in the Server script, and the third is the method parameter.

How to Run

Once editing is complete, click the Run button in the top left corner of the editor to execute the Client script and print the output.

Client Run

Supports JSX Syntax

Client scripts support JSX syntax, allowing you to directly write JSX components within the Client script and register them on the page. For example:

function onOpen(){ // Register components to the corresponding SLOT // including CUSTOM_HEADER, CUSTOM_FOOTER, CUSTOM_LEFT, CUSTOM_RIGHT univerAPI.registerUIPart( univerAPI.Enum.BuiltInUIPart.CUSTOM_HEADER, SpinComponent ) } function SpinComponent(){ // Get the antd component from the UI variable const Spin = univerAPI.UI.Spin; return <Spin /> }

Register JSX Component

You will be able to see the registered component on the page (upper left corner).

Preview JSX Component

Node Script

How to Create

In the Workspace, click the + button, and select the Node script type to create a Node script.

Node Script

How to Edit

Click the Node script to enter the editor. The editor supports Node.js syntax highlighting, code suggestions, and other features.

Node Editor

How to Run

Once editing is complete, click the Run button in the top left corner of the editor to execute the Node script and print the output.

Node Run

Python Script

How to Create

In the Workspace, click the + button, and select the Python script type to create a Python script.

Python Script

How to Edit

Click the Python script to enter the editor. The editor supports Python syntax highlighting, code suggestions, and other features.

Python Editor

How to Run

Once editing is complete, click the Run button in the top left corner of the editor to execute the Python script and print the output.

Python Run

Last updated on

Was this page helpful?