Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

docs: update README for all packages & add zh translations (#1467)

白熱5b82a0aa0e10
diff --git a/packages/core/README-zh.md b/packages/core/README-zh.md
new file mode 100644
index 0000000000..9a181d41a9
--- /dev/null
+++ b/packages/core/README-zh.md
@@ -0,0 +1,36 @@
+# @univerjs/core
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/core)](https://npmjs.org/package/@univerjs/core)
+[![license](https://img.shields.io/npm/l/@univerjs/core)](https://img.shields.io/npm/l/@univerjs/core)
+
+## 简介
+
+`@univerjs/core` 是 Univer 的核心包,它提供的基础能力包括:
+
+- 提供作为应用入口和其他 plugin 挂载点的 `Univer` 类型,以及管理不同类型文档的 `UniverDoc` 和 `UniverSheet` 类型
+- 各个类型文档的基本模型
+- 定义或者实现一些基础服务,例如
+ - 权限控制
+ - 命令系统
+ - Undo Redo
+ - 配置系统
+ - 日志系统
+ - 上下文系统
+ - 生命周期
+ - 本地存储
+ - 国际化
+ - 资源管理
+
+`@univerjs/core` 的 API 请参考 API 文档。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/core
+
+# 使用 pnpm
+pnpm add @univerjs/core
+```
diff --git a/packages/core/README.md b/packages/core/README.md
index da5712d3d0..7e0cc75980 100644
--- a/packages/core/README.md
+++ b/packages/core/README.md
@@ -5,12 +5,32 @@
## Introduction
-> Core library for Univer.
+`@univerjs/core` as its name shows, is the core package of Univer, and provides foundational capabilities including:
+
+* Provision of the Univer type, which serves as the entry point for applications and a mounting point for other plugins, as well as the UniverDoc and UniverSheet types for managing different document types
+* Basic models for each document type
+* Definition or implementation of several fundamental services, such as:
+ * Permission control
+ * Command system
+ * Undo/Redo
+ * Configuration system
+ * Logging system
+ * Context system
+ * Lifecycle
+ * Local storage
+ * Internationalization
+ * Resource management
+
+For more information about `@univerjs/core`'s API, please refer to the API documentation.
## Usage
### Installation
```shell
-npm i @univerjs/core
+# Using npm
+npm install @univerjs/core
+
+# Using pnpm
+pnpm add @univerjs/core
```
diff --git a/packages/design/README-zh.md b/packages/design/README-zh.md
new file mode 100644
index 0000000000..184a1ab0f4
--- /dev/null
+++ b/packages/design/README-zh.md
@@ -0,0 +1,28 @@
+# @univerjs/design
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/design)](https://npmjs.org/package/@univerjs/design)
+[![license](https://img.shields.io/npm/l/@univerjs/design)](https://img.shields.io/npm/l/@univerjs/design)
+
+## 简介
+
+为了让 Univer 的插件 UI 能够有更好的一致性,也为了降低用户自定义开发时的工作量,我们提供了一些基础的设计规范和组件。
+
+组件基于 React 和 less 开发,可以访问[组件库网站](https://univer-design.vercel.app)了解更多信息。
+
+![](./assets/design.jpeg)
+
+:::note
+如果你只需要扩展工具栏、右键菜单等,可以直接使用 @univerjs/ui 提供的扩展接口,无需自行实现 UI。请参考[扩展 UI](/guides/extend/ui)。
+:::
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/design
+
+# 使用 pnpm
+pnpm add @univerjs/design
+```
diff --git a/packages/design/README.md b/packages/design/README.md
index 240434e113..36149722ac 100644
--- a/packages/design/README.md
+++ b/packages/design/README.md
@@ -5,12 +5,24 @@
## Introduction
-> UI component library for building exceptional Univer.
+To ensure better consistency in the UI of Univer plugins and to reduce the effort required for custom development, we provide some fundamental design guidelines and components.
+
+The components are developed using React and less, and you can find out more information by visiting the [component library website](https://univer-design.vercel.app).
+
+![](./assets/design.jpeg)
+
+:::note
+If you only need to extend the toolbar, right-click menu, and so on, you can directly use the extension interfaces provided by `@univerjs/ui` without implementing the UI yourself. For more information, please refer to [Extending UI](/en-us/guides/extend/ui).
+:::
## Usage
### Installation
```shell
-npm i @univerjs/design
+# Using npm
+npm install @univerjs/design
+
+# Using pnpm
+pnpm add @univerjs/design
```
diff --git a/packages/design/assets/design.jpeg b/packages/design/assets/design.jpeg
new file mode 100644
index 0000000000..18ba3e7871
Binary files /dev/null and b/packages/design/assets/design.jpeg differ
diff --git a/packages/docs-ui/README-zh.md b/packages/docs-ui/README-zh.md
new file mode 100644
index 0000000000..58654134c0
--- /dev/null
+++ b/packages/docs-ui/README-zh.md
@@ -0,0 +1,24 @@
+# @univerjs/docs-ui
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/docs-ui)](https://npmjs.org/package/@univerjs/docs-ui)
+[![license](https://img.shields.io/npm/l/@univerjs/docs-ui)](https://img.shields.io/npm/l/@univerjs/docs-ui)
+
+## 简介
+
+`@univerjs/docs-ui` 提供了 Doc 的 UI。
+
+:::info
+`@univerjs/docs-ui` 仍在试验阶段,建议不要在生产环境中使用。你可以在[路线图](/guides/roadmap)了解迭代计划。
+:::
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/docs-ui
+
+# 使用 pnpm
+pnpm add @univerjs/docs-ui
+```
diff --git a/packages/docs-ui/README.md b/packages/docs-ui/README.md
index 0aeff285a6..61261401de 100644
--- a/packages/docs-ui/README.md
+++ b/packages/docs-ui/README.md
@@ -5,12 +5,20 @@
## Introduction
-> UI plugin for Univer Docs.
+`@univerjs/docs-ui` package provides the User Interface for Docs.
+
+:::info
+`@univerjs/docs-ui` is still in the experimental phase. It is not recommended for use in production environments. You can learn about the iteration plans on the [roadmap](/guides/roadmap).
+:::
## Usage
### Installation
```shell
-npm i @univerjs/docs-ui
+# Using npm
+npm install @univerjs/docs-ui
+
+# Using pnpm
+pnpm add @univerjs/docs-ui
```
diff --git a/packages/docs/README-zh.md b/packages/docs/README-zh.md
new file mode 100644
index 0000000000..ca0e68271a
--- /dev/null
+++ b/packages/docs/README-zh.md
@@ -0,0 +1,26 @@
+# @univerjs/docs
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/docs)](https://npmjs.org/package/@univerjs/docs)
+[![license](https://img.shields.io/npm/l/@univerjs/docs)](https://img.shields.io/npm/l/@univerjs/docs)
+
+## 简介
+
+`@univerjs/docs` 提供了富文本模型的基本业务,包括以下能力:
+
+* 提供选区逻辑
+* 更改富文本数据的 commands / mutations 等
+* 文档的 canvas 绘制
+
+`@univerjs/docs` 还为其他业务的编辑器提供支持,例如电子表格的单元格编辑器和公式编辑器等。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/docs
+
+# 使用 pnpm
+pnpm add @univerjs/docs
+```
diff --git a/packages/docs/README.md b/packages/docs/README.md
index fdcd909496..ce4998db9a 100644
--- a/packages/docs/README.md
+++ b/packages/docs/README.md
@@ -5,12 +5,22 @@
## Introduction
-> Core library for Univer Docs.
+`@univerjs/docs` package provides the fundamental operations for rich text models, including the following capabilities:
+
+* Logic for selection areas
+* Commands/mutations for altering rich text data
+* Canvas rendering for document presentation
+
+Additionally, `@univerjs/docs` offers support for editors in other domains, such as cell editors for spreadsheets and formula editors, among others.
## Usage
### Installation
```shell
-npm i @univerjs/docs
+# Using npm
+npm install @univerjs/docs
+
+# Using pnpm
+pnpm add @univerjs/docs
```
diff --git a/packages/engine-formula/README-zh.md b/packages/engine-formula/README-zh.md
new file mode 100644
index 0000000000..75250bed83
--- /dev/null
+++ b/packages/engine-formula/README-zh.md
@@ -0,0 +1,20 @@
+# @univerjs/engine-formula
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/engine-formula)](https://npmjs.org/package/@univerjs/engine-formula)
+[![license](https://img.shields.io/npm/l/@univerjs/engine-formula)](https://img.shields.io/npm/l/@univerjs/engine-formula)
+
+## 简介
+
+`@univerjs/engine-formula` 是一个公式引擎,它提供了一套公式计算的基础能力。包括公式字符串解析,公式计算,公式依赖分析等。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/engine-formula
+
+# 使用 pnpm
+pnpm add @univerjs/engine-formula
+```
diff --git a/packages/engine-formula/README.md b/packages/engine-formula/README.md
index 48c880ce3a..2eddb5e897 100644
--- a/packages/engine-formula/README.md
+++ b/packages/engine-formula/README.md
@@ -5,12 +5,16 @@
## Introduction
-> This plugin provides formula services to other modules of Univer.
+The `@univerjs/engine-formula` is a formula engine that provides fundamental capabilities for formula computation, including but not limited to: formula string parsing, formula calculation, and formula dependency analysis.
## Usage
### Installation
```shell
-npm i @univerjs/engine-formula
+# Using npm
+npm install @univerjs/engine-formula
+
+# Using pnpm
+pnpm add @univerjs/engine-formula
```
diff --git a/packages/engine-numfmt/README-zh.md b/packages/engine-numfmt/README-zh.md
new file mode 100644
index 0000000000..634a1791fa
--- /dev/null
+++ b/packages/engine-numfmt/README-zh.md
@@ -0,0 +1,20 @@
+# @univerjs/engine-numfmt
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/engine-numfmt)](https://npmjs.org/package/@univerjs/engine-numfmt)
+[![license](https://img.shields.io/npm/l/@univerjs/engine-numfmt)](https://img.shields.io/npm/l/@univerjs/engine-numfmt)
+
+## 简介
+
+`@univerjs/engine-formula` 是一个公式引擎,它提供了一套公式计算的基础能力。包括公式字符串解析,公式计算,公式依赖分析等。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/engine-numfmt
+
+# 使用 pnpm
+pnpm add @univerjs/engine-numfmt
+```
diff --git a/packages/engine-numfmt/README.md b/packages/engine-numfmt/README.md
index 6b997b559c..eee9c25597 100644
--- a/packages/engine-numfmt/README.md
+++ b/packages/engine-numfmt/README.md
@@ -3,14 +3,18 @@
[![npm version](https://img.shields.io/npm/v/@univerjs/engine-numfmt)](https://npmjs.org/package/@univerjs/engine-numfmt)
[![license](https://img.shields.io/npm/l/@univerjs/engine-numfmt)](https://img.shields.io/npm/l/@univerjs/engine-numfmt)
-## Introduction
+## 简介
-> This plugin provides numfmt services to other modules of Univer.
+The `@univerjs/engine-formula` is a formula engine that provides fundamental capabilities for formula computation, including but not limited to: formula string parsing, formula calculation, and formula dependency analysis.
## Usage
### Installation
```shell
-npm i @univerjs/engine-numfmt
+# Using npm
+npm install @univerjs/engine-numfmt
+
+# Using pnpm
+pnpm add @univerjs/engine-numfmt
```
diff --git a/packages/engine-render/README-zh.md b/packages/engine-render/README-zh.md
new file mode 100644
index 0000000000..c93f5275c8
--- /dev/null
+++ b/packages/engine-render/README-zh.md
@@ -0,0 +1,22 @@
+# @univerjs/engine-render
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/engine-render)](https://npmjs.org/package/@univerjs/engine-render)
+[![license](https://img.shields.io/npm/l/@univerjs/engine-render)](https://img.shields.io/npm/l/@univerjs/engine-render)
+
+## Introduction
+
+`@univerjs/engine-render` 提供在 canvas 元素上渲染 Univer 文档的能力。包括绘制图形元素、处理光标交互、处理滚动缩放等能力。
+
+各类文档的渲染层在 `@univerjs/engine-render` 提供的基础设施上进行扩展。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/engine-render
+
+# 使用 pnpm
+pnpm add @univerjs/engine-render
+```
diff --git a/packages/engine-render/README.md b/packages/engine-render/README.md
index 96a97a7fe2..caee487918 100644
--- a/packages/engine-render/README.md
+++ b/packages/engine-render/README.md
@@ -5,13 +5,18 @@
## Introduction
-> This plugin provides render services to other modules of Univer.
+The `@univerjs/engine-render` provides the ability to render Univer documents on a canvas element, including the capability to draw graphical elements, handle cursor interactions, and process scrolling and zooming.
+
+The rendering layer for various document types is extended based on the foundational infrastructure provided by `@univerjs/engine-render`.
## Usage
### Installation
```shell
-npm i @univerjs/engine-render
+# Using npm
+npm install @univerjs/engine-render
+
+# Using pnpm
+pnpm add @univerjs/engine-render
```
-1
\ No newline at end of file
diff --git a/packages/facade/README-zh.md b/packages/facade/README-zh.md
new file mode 100644
index 0000000000..1a9b36a4e8
--- /dev/null
+++ b/packages/facade/README-zh.md
@@ -0,0 +1,22 @@
+# @univerjs/facade
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/facade)](https://npmjs.org/packages/@univerjs/facade)
+[![license](https://img.shields.io/npm/l/@univerjs/facade)](https://img.shields.io/npm/l/@univerjs/facade)
+
+## 简介
+
+在 Univer 当中,除了使用底层的 API 之外,你还可以使用 `@univerjs/facade` 提供的 Facade API,它是对底层 API 的封装,更加简单易用。
+
+你可以通过阅读[这篇文档](https://univer.ai/en-us/guides/facade/)了解如何使用 Facade API。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/facade
+
+# 使用 pnpm
+pnpm add @univerjs/facade
+```
diff --git a/packages/facade/README.md b/packages/facade/README.md
index 11f90a92e5..2f8627c0b5 100644
--- a/packages/facade/README.md
+++ b/packages/facade/README.md
@@ -5,14 +5,18 @@
## Introduction
-Facade works as a API layer over all other Univer packages (expect for Uniscript) so that you can use Univer without knowing the details of the architecture.
+In Univer, in addition to using the low-level APIs, you can also use the Facade API provided by `@univerjs/facade`, which is a higher-level abstraction of the low-level APIs, making it easier to use.
-Though Facade may suites for most of the use cases, you may find it more powerful and easier to extend Univer by using the packages directly.
+You can learn how to use the Facade API by reading [this document](https://univer.ai/en-us/guides/facade/).
## Usage
### Installation
```shell
-npm i @univerjs/facade
+# Using npm
+npm install @univerjs/facade
+
+# Using pnpm
+pnpm add @univerjs/facade
```
diff --git a/packages/find-replace/README-zh.md b/packages/find-replace/README-zh.md
new file mode 100644
index 0000000000..357db9b8fd
--- /dev/null
+++ b/packages/find-replace/README-zh.md
@@ -0,0 +1,20 @@
+# @univerjs/find-replace
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/find-replace)](https://npmjs.org/packages/@univerjs/find-replace)
+[![license](https://img.shields.io/npm/l/@univerjs/find-replace)](https://img.shields.io/npm/l/@univerjs/find-replace)
+
+## 简介
+
+TODO: Not yet written.
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/find-replace
+
+# 使用 pnpm
+pnpm add @univerjs/find-replace
+```
diff --git a/packages/find-replace/README.md b/packages/find-replace/README.md
index c8e3233b48..2d6b636bfc 100644
--- a/packages/find-replace/README.md
+++ b/packages/find-replace/README.md
@@ -5,12 +5,16 @@
## Introduction
-> TODO: Introduction
+TODO: Not yet written.
## Usage
### Installation
```shell
-npm i @univerjs/find-replace
+# Using npm
+npm install @univerjs/find-replace
+
+# Using pnpm
+pnpm add @univerjs/find-replace
```
diff --git a/packages/network/README-zh.md b/packages/network/README-zh.md
new file mode 100644
index 0000000000..05c52d35fd
--- /dev/null
+++ b/packages/network/README-zh.md
@@ -0,0 +1,20 @@
+# @univerjs/network
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/network)](https://npmjs.org/package/@univerjs/network)
+[![license](https://img.shields.io/npm/l/@univerjs/network)](https://img.shields.io/npm/l/@univerjs/network)
+
+## 简介
+
+`@univerjs/network` 提供了基础的网络服务能力,主要用于协同编辑场景。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/network
+
+# 使用 pnpm
+pnpm add @univerjs/network
+```
diff --git a/packages/network/README.md b/packages/network/README.md
index 8033a58574..35c64eced2 100644
--- a/packages/network/README.md
+++ b/packages/network/README.md
@@ -5,12 +5,16 @@
## Introduction
-> This plugin provides network services to other modules of Univer.
+The `@univerjs/network` library provides basic network service capabilities, primarily for use in collaborative editing scenarios.
## Usage
### Installation
```shell
-npm i @univerjs/network
+# Using npm
+npm install @univerjs/network
+
+# Using pnpm
+pnpm add @univerjs/network
```
diff --git a/packages/rpc/README-zh.md b/packages/rpc/README-zh.md
new file mode 100644
index 0000000000..326b0671dc
--- /dev/null
+++ b/packages/rpc/README-zh.md
@@ -0,0 +1,22 @@
+# @univerjs/rpc
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/rpc)](https://npmjs.org/package/@univerjs/rpc)
+[![license](https://img.shields.io/npm/l/@univerjs/rpc)](https://img.shields.io/npm/l/@univerjs/rpc)
+
+## 简介
+
+在处理一些比较耗时的任务——例如公式计算——时,Univer 可以将它们转移到主线程之外的地方进行,例如 Web Worker 线程中。@univerjs/rpc 提供了一套 RPC 机制,使得在主线程和其他线程之间进行通信变得简单。
+
+详情请参考 [Web Worker 架构](https://univer.ai/guides/architecture/web-worker/)。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/rpc
+
+# 使用 pnpm
+pnpm add @univerjs/rpc
+```
diff --git a/packages/rpc/README.md b/packages/rpc/README.md
index d19e48b615..c0cc70291c 100644
--- a/packages/rpc/README.md
+++ b/packages/rpc/README.md
@@ -5,16 +5,18 @@
## Introduction
-> Univer RPC provides RPC framework for Univer.
+When handling some time-intensive tasks, such as formula computation, Univer can offload them to a location outside of the main thread, such as a Web Worker thread. The `@univerjs/rpc` library provides an RPC mechanism that simplifies communication between the main thread and other threads.
+
+For more information, see the [Architecture of Web Worker](https://univer.ai/en-us/guides/architecture/web-worker/).
## Usage
### Installation
```shell
-npm i @univerjs/rpc
-```
+# Using npm
+npm install @univerjs/rpc
-### API
-
-Check [Univer](https://github.com/dream-num/univer/)
+# Using pnpm
+pnpm add @univerjs/rpc
+```
diff --git a/packages/sheets-find-replace/README-zh.md b/packages/sheets-find-replace/README-zh.md
new file mode 100644
index 0000000000..e3501941df
--- /dev/null
+++ b/packages/sheets-find-replace/README-zh.md
@@ -0,0 +1,20 @@
+# @univerjs/sheets-find
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-find)](https://npmjs.org/package/@univerjs/sheets-find)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-find)](https://img.shields.io/npm/l/@univerjs/sheets-find)
+
+## 简介
+
+TODO: Not written yet.
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/sheets-find
+
+# 使用 pnpm
+pnpm add @univerjs/sheets-find
+```
diff --git a/packages/sheets-find-replace/README.md b/packages/sheets-find-replace/README.md
index ed70919bbb..1e40fbfbc5 100644
--- a/packages/sheets-find-replace/README.md
+++ b/packages/sheets-find-replace/README.md
@@ -5,12 +5,16 @@
## Introduction
-> Find plugin for Univer Sheets.
+TODO: Not written yet.
## Usage
### Installation
```shell
-npm i @univerjs/sheets-find
+# Using npm
+npm install @univerjs/sheets-find
+
+# Using pnpm
+pnpm add @univerjs/sheets-find
```
diff --git a/packages/sheets-formula/README-zh.md b/packages/sheets-formula/README-zh.md
new file mode 100644
index 0000000000..1022410bb2
--- /dev/null
+++ b/packages/sheets-formula/README-zh.md
@@ -0,0 +1,793 @@
+# @univerjs/sheets-formula
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-formula)](https://npmjs.org/package/@univerjs/sheets-formula)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-formula)](https://img.shields.io/npm/l/@univerjs/sheets-formula)
+
+## 简介
+
+`@univerjs/sheets-formula` 提供了在电子表格中编辑公式的能力,例如自动补全、公式提示、公式的下拉填充以及复制粘贴等等。
+
+:::note
+公式计算是电子表格的核心功能之一,因此公式计算调度是在 `@univerjs/sheets` 中进行的。
+:::
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/sheets-formula
+
+# 使用 pnpm
+pnpm add @univerjs/sheets-formula
+```
+
+### 添加公式前置条件
+
+如果官方提供的公式不满足您的需求,可以自己扩展公式。根据不同的需求,我们提供了多种方式来支持注册一个或多个自定义公式。
+
+您需要先准备好公式提示所需要的国际化文案和算法,然后参考我们的[贡献指南](https://github.com/dream-num/univer/blob/dev/CONTRIBUTING.md)运行 Univer 项目,再开始添加公式。
+
+### 如何使用 Uniscript 添加公式
+
+使用 Uniscript 脚本,可以方便快速的在当前 Univer 实例中注册自定义公式。
+
+如下案例所示,使用 `registerFunction` 将一个 `CUSTOMSUM` 公式所需要的算法、名称、描述一次性注册到公式插件,执行之后就可以使用公式了。在任一空白单元格输入 `=CUSTOMSUM` 可以看到提示。
+
+```js
+univerAPI.registerFunction({
+ calculate: [
+ [function (...variants) {
+ let sum = 0;
+
+ for(const variant of variants){
+ sum += Number(variant) || 0;
+ }
+
+ return sum;
+ }, 'CUSTOMSUM', '求参数的和'],
+ // ... 更多公式
+ ]
+})
+```
+
+使用 `unregisterFunction` 方法能快速卸载自定义公式
+
+```ts
+univerAPI.unregisterFunction({
+ functionNames: ['CUSTOMSUM']
+})
+```
+
+如果想要提供更完善的国际化内容和描述,还可以配置 `locales` 和 `description` 字段。如下所示。
+
+```js
+const FUNCTION_NAMES_USER = {
+ CUSTOMSUM: 'CUSTOMSUM'
+}
+univerAPI.registerFunction({
+ locales:{
+ 'zhCN': {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: '将单个值、单元格引用或是区域相加,或者将三者的组合相加。',
+ abstract: '求参数的和',
+ links: [
+ {
+ title: '教学',
+ url: 'https://support.microsoft.com/zh-cn/office/sum-%E5%87%BD%E6%95%B0-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要相加的第一个数字。 该数字可以是 4 之类的数字,B6 之类的单元格引用或 B2:B8 之类的单元格范围。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '这是要相加的第二个数字。 可以按照这种方式最多指定 255 个数字。',
+ },
+ },
+ },
+ // ... 更多公式
+ },
+ },
+ 'enUS':{
+ formulaCustom:{
+ CUSTOMSUM: {
+ description: `You can add individual values, cell references or ranges or a mix of all three.`,
+ abstract: `Adds its arguments`,
+ links: [
+ {
+ title: 'Instruction',
+ url: 'https://support.microsoft.com/en-us/office/sum-function-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number you want to add. The number can be like 4, a cell reference like B6, or a cell range like B2:B8.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'This is the second number you want to add. You can specify up to 255 numbers in this way.',
+ },
+ },
+ },
+ }
+ }
+ },
+ description:[
+ {
+ functionName: FUNCTION_NAMES_USER.CUSTOMSUM,
+ aliasFunctionName: 'formulaCustom.CUSTOMSUM.aliasFunctionName',
+ functionType: 15,
+ description: 'formulaCustom.CUSTOMSUM.description',
+ abstract: 'formulaCustom.CUSTOMSUM.abstract',
+ functionParameter: [
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number1.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number2.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+ // ... 更多公式
+ ],
+ calculate: [
+ [function (...variants) {
+ let sum = 0;
+
+ for(const variant of variants){
+ sum += Number(variant) || 0;
+ }
+
+ return sum;
+ }, FUNCTION_NAMES_USER.CUSTOMSUM],
+ // ... 更多公式
+ ]
+})
+```
+
+说明
+
+- `locales` 下可以设置多种语言,命名规则参考 [LocaleType](/api/core/enums/LocaleType.html)。可以在 `functionList` 下添加多个公式的翻译。详细的字段说明请参考[如何在 UniverFormulaEnginePlugin 中添加公式](./#如何在-univerformulaengineplugin-中添加公式)的部分。
+- `description` 设置自定义公式的描述。
+- `calculate` 编写计算公式的具体算法和名称映射。入参为使用公式时用户输入的内容,可能为数字、字符串、布尔值,或者一个范围,也是返回同样的格式。
+
+同样的, 如果使用 `unregisterFunction` 方法,推荐你把国际化文件也移除。下方示例是将中文和英文的 `formulaCustom` 节点移除。
+
+```ts
+univerAPI.unregisterFunction({
+ localeKeys: {
+ 'zhCN': ['formulaCustom'],
+ 'enUS': ['formulaCustom'],
+ },
+ functionNames: ['CUSTOMSUM']
+})
+```
+
+Uniscript 底层使用了 `@univerjs/facade`,你也可以直接在项目中使用类似 Uniscript 的 API,请参考 [注册公式](/guides/facade/register-function)。
+
+## 如何在初始化 Univer 时添加公式
+
+按照以下步骤来实现一个自定义公式 `CUSTOMSUM`。
+
+你可以新建一个 `custom-function.ts` 文件来专门放置自定义公式相关模块,或者直接写在 `univer` 初始化之前。
+
+1. 定义公式名称
+
+ 首先为公式起一个名称,我们要求不能同已有公式名称重复,已有公式主要是从 [Office Excel](https://support.microsoft.com/zh-cn/office/excel-%E5%87%BD%E6%95%B0-%E6%8C%89%E7%B1%BB%E5%88%AB%E5%88%97%E5%87%BA-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb) 参考。
+
+ 我们把多个自定义公式搜集在一个枚举中。
+
+ ```ts
+ /**
+ * function name
+ */
+ export enum FUNCTION_NAMES_USER {
+ CUSTOMSUM = "CUSTOMSUM",
+ }
+ ```
+
+2. 定义国际化
+
+ 定义你所需要的国际化内容,详细的字段说明请参考[如何在 UniverFormulaEnginePlugin 中添加公式](./#如何在-univerformulaengineplugin-中添加公式)的部分。同样的,多个公式就用公式名称作为 `key` 值区分。
+
+ ```ts
+ /**
+ * i18n
+ */
+ export const functionEnUS = {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: `You can add individual values, cell references or ranges or a mix of all three.`,
+ abstract: `Adds its arguments`,
+ links: [
+ {
+ title: 'Instruction',
+ url: 'https://support.microsoft.com/en-us/office/sum-function-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number you want to add. The number can be like 4, a cell reference like B6, or a cell range like B2:B8.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'This is the second number you want to add. You can specify up to 255 numbers in this way.',
+ },
+ },
+ },
+ },
+ };
+
+ export const functionZhCN = {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: '将单个值、单元格引用或是区域相加,或者将三者的组合相加。',
+ abstract: '求参数的和',
+ links: [
+ {
+ title: '教学',
+ url: 'https://support.microsoft.com/zh-cn/office/sum-%E5%87%BD%E6%95%B0-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要相加的第一个数字。 该数字可以是 4 之类的数字,B6 之类的单元格引用或 B2:B8 之类的单元格范围。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '这是要相加的第二个数字。 可以按照这种方式最多指定 255 个数字。',
+ },
+ },
+ },
+ },
+ };
+ ```
+
+3. 注册国际化
+
+ 在原有的国际化对象中扩展你定义的国际化内容。
+
+ ```ts
+ export const locales = {
+ [LocaleType.EN_US]: {
+ ...UniverSheetsEnUS,
+ ...UniverDocsUIEnUS,
+ ...UniverSheetsUIEnUS,
+ ...UniverUiEnUS,
+ ...UniverDesignEnUS,
+ ...functionEnUS,
+ },
+ [LocaleType.ZH_CN]: {
+ ...functionZhCN,
+ },
+ };
+ ```
+
+4. 定义描述
+
+ 公式的描述中主要是配置国际化字段,用于公式搜索提示、详情面板等。
+
+ ```ts
+ import type { IFunctionInfo } from '@univerjs/engine-formula';
+ import { FunctionType } from '@univerjs/engine-formula';
+
+ /**
+ * description
+ */
+ export const FUNCTION_LIST_USER: IFunctionInfo[] = [
+ {
+ functionName: FUNCTION_NAMES_USER.CUSTOMSUM,
+ aliasFunctionName: 'formulaCustom.CUSTOMSUM.aliasFunctionName',
+ functionType: FunctionType.User,
+ description: 'formulaCustom.CUSTOMSUM.description',
+ abstract: 'formulaCustom.CUSTOMSUM.abstract',
+ functionParameter: [
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number1.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number2.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+ ];
+ ```
+
+5. 注册描述
+
+ 注册公式插件时传入你定义的描述对象。
+
+ ```ts
+ // univer
+ univer.registerPlugin(UniverSheetsFormulaPlugin, {
+ description: FUNCTION_LIST_USER,
+ });
+ ```
+
+6. 定义公式算法
+
+ 编写具体的公式计算逻辑,并将算法和公式名称映射起来。
+
+ ```ts
+ import type { ArrayValueObject, BaseValueObject, IFunctionInfo } from '@univerjs/engine-formula';
+ import { BaseFunction, FunctionType, NumberValueObject } from '@univerjs/engine-formula';
+
+ /**
+ * Function algorithm
+ */
+ export class Customsum extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ let accumulatorAll: BaseValueObject = new NumberValueObject(0);
+ for (let i = 0; i < variants.length; i++) {
+ let variant = variants[i];
+
+ if (variant.isError()) {
+ return variant;
+ }
+
+ if (accumulatorAll.isError()) {
+ return accumulatorAll;
+ }
+
+ if (variant.isArray()) {
+ variant = (variant as ArrayValueObject).sum();
+ }
+
+ accumulatorAll = accumulatorAll.plus(variant as BaseValueObject);
+ }
+
+ return accumulatorAll;
+ }
+ }
+
+ // Mapping of algorithms and names
+ export const functionUser = [[Customsum, FUNCTION_NAMES_USER.CUSTOMSUM]];
+ ```
+
+7. 注册公式算法
+
+ 在 `UniverFormulaEnginePlugin` 传入你定义的公式算法对象。
+
+ ```ts
+ univer.registerPlugin(UniverFormulaEnginePlugin, {
+ function: functionUser,
+ });
+ ```
+
+ 请注意:如果 `UniverFormulaEnginePlugin` 在 `worker` 中有实例化,则需要在 `worker` 中的 `UniverFormulaEnginePlugin` 注册公式算法,否则无法获取执行自定义公式。
+
+8. 测试
+
+ 到这里就完成了自定义公式的开发,现在可以测试一下。任一空白单元格输入 `=CUSTOMSUM` 预期能得到公式提示。这里提供一个[自定义公式 Demo](/playground?title=Custom%20Function),供参考。
+
+### 如何在第三方插件中添加公式
+
+如果你正在开发一个 Univer 插件,你可以直接在这个插件中新增自定义公式,方便代码在一个插件仓库中管理。
+
+我们内部的 `UniverFormulaEnginePlugin` 插件提供了一个 `function.service`,专门用来注册公式的描述和算法。
+
+首先参考 [自定义插件](/guides/extend/write-a-plugin/),新建一个插件,然后就可以开始添加自定义公式。
+
+1. `common` 文件内新建 `custom-function.ts` 文件,将公式所需要的基础模块全部写好。
+
+ ```ts
+ import type { ArrayValueObject, BaseValueObject, IFunctionInfo } from '@univerjs/engine-formula';
+ import { BaseFunction, FunctionType, NumberValueObject } from '@univerjs/engine-formula';
+
+ /**
+ * function name
+ */
+ export enum FUNCTION_NAMES_USER {
+ CUSTOMSUM = 'CUSTOMSUM',
+ }
+
+ /**
+ * i18n
+ */
+ export const functionEnUS = {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: `You can add individual values, cell references or ranges or a mix of all three.`,
+ abstract: `Adds its arguments`,
+ links: [
+ {
+ title: 'Instruction',
+ url: 'https://support.microsoft.com/en-us/office/sum-function-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number you want to add. The number can be like 4, a cell reference like B6, or a cell range like B2:B8.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'This is the second number you want to add. You can specify up to 255 numbers in this way.',
+ },
+ },
+ },
+ },
+ };
+
+ export const functionZhCN = {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: '将单个值、单元格引用或是区域相加,或者将三者的组合相加。',
+ abstract: '求参数的和',
+ links: [
+ {
+ title: '教学',
+ url: 'https://support.microsoft.com/zh-cn/office/sum-%E5%87%BD%E6%95%B0-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要相加的第一个数字。 该数字可以是 4 之类的数字,B6 之类的单元格引用或 B2:B8 之类的单元格范围。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '这是要相加的第二个数字。 可以按照这种方式最多指定 255 个数字。',
+ },
+ },
+ },
+ },
+ };
+
+ /**
+ * description
+ */
+ export const FUNCTION_LIST_USER: IFunctionInfo[] = [
+ {
+ functionName: FUNCTION_NAMES_USER.CUSTOMSUM,
+ aliasFunctionName: 'formulaCustom.CUSTOMSUM.aliasFunctionName',
+ functionType: FunctionType.User,
+ description: 'formulaCustom.CUSTOMSUM.description',
+ abstract: 'formulaCustom.CUSTOMSUM.abstract',
+ functionParameter: [
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number1.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number2.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+ ];
+
+ /**
+ * Function algorithm
+ */
+ export class Customsum extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ let accumulatorAll: BaseValueObject = new NumberValueObject(0);
+ for (let i = 0; i < variants.length; i++) {
+ let variant = variants[i];
+
+ if (variant.isError()) {
+ return variant;
+ }
+
+ if (accumulatorAll.isError()) {
+ return accumulatorAll;
+ }
+
+ if (variant.isArray()) {
+ variant = (variant as ArrayValueObject).sum();
+ }
+
+ accumulatorAll = accumulatorAll.plus(variant as BaseValueObject);
+ }
+
+ return accumulatorAll;
+ }
+ }
+
+ export const functionUser = [[Customsum, FUNCTION_NAMES_USER.CUSTOMSUM]];
+ ```
+
+2. `controllers` 文件夹下新建 `custom-description.controller.ts` 用于注册公式国际化内容和描述。
+
+ ```ts
+ import { Disposable, LifecycleStages, LocaleService, OnLifecycle } from '@univerjs/core';
+ import { Inject } from '@wendellhu/redi';
+
+ import { FUNCTION_LIST_USER, functionEnUS, functionZhCN } from '../common/custom-function';
+ import { IDescriptionService } from '../services/description.service';
+
+ @OnLifecycle(LifecycleStages.Ready, CustomDescriptionController)
+ export class CustomDescriptionController extends Disposable {
+ constructor(
+ @IDescriptionService private readonly _descriptionService: IDescriptionService,
+ @Inject(LocaleService) private readonly _localeService: LocaleService
+ ) {
+ super();
+
+ this._initialize();
+ }
+
+ private _initialize(): void {
+ this._registerLocales();
+ this._registerCustomDescriptions();
+ }
+
+ private _registerLocales() {
+ this._localeService.load({
+ zhCN: functionZhCN,
+ enUS: functionEnUS,
+ });
+ }
+
+ private _registerCustomDescriptions() {
+ this._descriptionService.registerDescription(FUNCTION_LIST_USER);
+ }
+ }
+ ```
+
+3. `controllers` 文件夹下新建 `custom-function.controller.ts` 用于注册公式算法。
+
+ ```ts
+ import { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';
+ import type { BaseFunction, IFunctionNames } from '@univerjs/engine-formula';
+ import { IFunctionService } from '@univerjs/engine-formula';
+ import { type Ctor } from '@wendellhu/redi';
+
+ import { functionUser } from '../common/custom-function';
+
+ @OnLifecycle(LifecycleStages.Ready, CustomFunctionController)
+ export class CustomFunctionController extends Disposable {
+ constructor(@IFunctionService private readonly _functionService: IFunctionService) {
+ super();
+
+ this._initialize();
+ }
+
+ private _initialize(): void {
+ this._registerCustomFunctions();
+ }
+
+ private _registerCustomFunctions() {
+ const functions: BaseFunction[] = [...functionUser].map((registerObject) => {
+ const Func = registerObject[0] as Ctor<BaseFunction>;
+ const name = registerObject[1] as IFunctionNames;
+
+ return new Func(name);
+ });
+
+ this._functionService.registerExecutors(...functions);
+ }
+ }
+ ```
+
+4. 在插件入口文件 `plugin.ts` 中,将 `custom-description.controller.ts` 和 `custom-function.controller.ts` 注册到 DI 系统中。
+
+ ```ts
+ initialize(): void {
+ // ... 其它逻辑
+
+ const dependencies: Dependency[] = [
+ // ... 其它模块
+ [CustomFunctionController],
+ [CustomDescriptionController],
+ ];
+
+ dependencies.forEach((dependency) => this._injector.add(dependency));
+ }
+ ```
+
+ 启动 Univer,任一空白单元格输入 `=CUSTOMSUM` 即可测试这个新添加的公式。
+
+请注意:如果 `UniverFormulaEnginePlugin` 在 `worker` 中有实例化,则需要在 `worker`中注册公式算法,否则无法获取执行自定义公式。
+除了通过 `UniverFormulaEnginePlugin` 配置的形式来注册,还可以将公式算法模块单独包装成一个插件来注册。
+
+首先 `plugin.ts` 中就不需要注册 `CustomFunctionController` 了,同级目录新建一个 `custom-function-plugin.ts`,专门用于注册 `CustomFunctionController`。
+
+```ts
+import { Plugin, PluginType } from '@univerjs/core';
+import type { Dependency } from '@wendellhu/redi';
+import { Inject, Injector } from '@wendellhu/redi';
+
+import { FORMULA_UI_PLUGIN_NAME } from './common/plugin-name';
+import { CustomFunctionController } from './controllers/custom-function.controller';
+
+export class UniverSheetsCustomFunctionPlugin extends Plugin {
+ static override type = PluginType.Sheet;
+
+ constructor(@Inject(Injector) override readonly _injector: Injector) {
+ super(FORMULA_UI_PLUGIN_NAME);
+ }
+
+ initialize(): void {
+ const dependencies: Dependency[] = [[CustomFunctionController]];
+
+ dependencies.forEach((dependency) => this._injector.add(dependency));
+ }
+
+ override onReady(): void {
+ this.initialize();
+ }
+}
+```
+
+然后在 `index.ts` 中导出
+
+```ts
+export { UniverSheetsFormulaPlugin } from './formula-ui-plugin';
+```
+
+最后你的 `worker` 入口初始化这个插件。
+
+```ts
+import { UniverSheetsCustomFunctionPlugin } from '@univerjs/sheets-formula';
+
+// ... 初始化其他插件
+univer.registerPlugin(UniverSheetsCustomFunctionPlugin);
+```
+
+这样就可以在 `worker` 中注册公式了。
+
+### 如何在 UniverFormulaEnginePlugin 中添加公式
+
+#### 参考文档
+
+[Office Excel 函数(按类别列出)](https://support.microsoft.com/zh-cn/office/excel-%E5%87%BD%E6%95%B0-%E6%8C%89%E7%B1%BB%E5%88%AB%E5%88%97%E5%87%BA-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb)
+
+#### 类别
+
+详细 API 参考 [FunctionType](/api/engine-formula/enums/FunctionType.html)
+
+- Financial
+- Date
+- Math
+- Statistical
+- Lookup
+- Database
+- Text
+- Logical
+- Information
+- Engineering
+- Cube
+- Compatibility
+- Web
+- Array
+- Univer
+- User
+
+#### 要求
+
+要实现一个公式,需要添加公式描述、国际化和公式算法,以 `SUMIF` 函数的写法为例作为参考
+
+1. 添加函数名称
+
+ 位置在 [packages/engine-formula/src/functions/math/function-names.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/function-names.ts)。
+
+ 每个分类都有一个文件夹,包含一个 `function-names` 文件用于统一管理这个分类的所有函数名。我们先添加上函数名称,在 `sheets-formula` 插件中会用到。
+
+ 注意,Excel 中一个函数可能属于多个分类,比如 `FLOOR` 在兼容性和数学函数中出现,我们将它归类到数学分类下。其他函数也是这样处理,以确切的分类为依据。
+
+ > 大多数 Excel 函数已经写好了函数名。新的函数可以在末尾添加
+
+2. 国际化文件
+
+ 位置在 [packages/sheets-formula/src/locale/function-list/math/en-US.ts](https://github.com/dream-num/univer/blob/dev/packages/sheets-formula/src/locale/function-list/math/en-US.ts)。
+
+ 国际化也是一个分类一个文件。简介从 Office 函数分类页参考。
+ ![office excel](./assets/img/office-excel.png)
+
+ 函数描述和参数描述从 Office 函数详情页参考
+ ![sumif](./assets//img/sumif.png)
+
+ 大部分的函数名称我们已经写好了基础的描述、简介、链接、参数结构,推荐您在此基础上进行修改,如果没有的函数需要自己加在末尾。
+
+ 要求:
+
+ - 函数翻译的参数 `key` 使用这个函数的每个参数英文名称,比如 `SUMIF`,除非有错误,一般不用改动
+ - `description` 参数需要综合下内容进行提取,因为有的 Excel 描述很长,需要简化
+ - `abstract` 和 `links` 基本上不需要做改动
+ - `aliasFunctionName` 是可选参数,大部分公式不需要填写(也可以只设置某个国家的别名),暂时还未找到有公式别名文档来参考。目前找到一个函数翻译插件可能提供类似功能 [Excel 函数翻译工具](https://support.microsoft.com/zh-cn/office/excel-%E5%87%BD%E6%95%B0%E7%BF%BB%E8%AF%91%E5%B7%A5%E5%85%B7-f262d0c0-991c-485b-89b6-32cc8d326889)
+ - `functionParameter` 中需要为每个参数设定一个名称,我们推荐根据参数的含义进行变化,比如数值类型的 `key` 为 `number`(仅有一个数值参数的时候)或者 `number1`、`number2`(有多个数值参数的时候),范围为 `range`,条件为 `criteria`,求和范围为 `sum_range`(多个单词之间用 `_` 分割)
+ - Office 函数文档中文翻译猜测用的机翻,部分翻译不容易理解,需要自己修改,一部分专用名词如下。
+ - 单元格参考 => 单元格引用
+ - 数字类型的参数统一翻译为:数值
+ - `abstract` 结尾不要加句号(用在用户输入单元格时的搜索列表中,但是部分国家的语言有加句号的习惯,比如日本语,参照 Excel 的简介信息即可),`description` 和 `detail` 结尾加句号(用在描述中)
+ - 英文句子的首字母大写
+ - 注意所有的现有的国际化文件都需要填写,目前只有中英日(Excel 介绍页底部可以切换语言)
+
+3. 公式描述
+
+ `SUMIF` 属于 `math` 分类,描述信息在 [packages/sheets-formula/src/services/function-list/math.ts](https://github.com/dream-num/univer/blob/dev/packages/sheets-formula/src/services/function-list/math.ts),这个文件负责整个 `math` 分类所有函数。
+
+ 大部分的函数名称我们已经写好了基础的描述结构,推荐您在此基础上进行修改,如果没有的函数需要自己加在末尾。
+
+ 要求:
+
+ - 在 `FUNCTION_LIST_MATH` 数组中增加公式,我们建议保持和国际化文件中的顺序一致,便于管理和查找
+ - `functionName` 需要引用之前定义的 `FUNCTION_NAMES_MATH` 枚举
+ - `aliasFunctionName` 也是可选的,如果国际化文件中没有别名,这里也不用添加
+ - 国际化字段注意对应好函数名和参数名
+ - 注意修改函数参数的信息, `example` 参数示例(比如范围写 `"A1:A20"`,条件写 `">5"` ),`require` 是否必需(1 必需,0 可选) ,`repeat` 是否允许重复(1 允许重复,0 不允许重复),详细说明参考文件内的接口 [IFunctionParam](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/basics/function.ts)
+
+4. 公式算法
+
+ 位置在 [packages/engine-formula/src/functions/math/sumif/index.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/sumif/index.ts)。
+
+ 在当前公式的分类文件夹下新建公式文件夹,一个公式一个文件夹。然后新建 `index.ts` 文件来写公式算法,公式 `class` 的名称采用大驼峰的写法,认为公式是一个单词,带 `_` 或者 `.` 的公式认为是两个单词,比如
+
+ - `SUMIF` => `Sumif`
+ - `NETWORKDAYS.INTL` => `Networkdays_Intl`
+ - `ARRAY_CONSTRAIN` => `Array_Constrain`
+
+ 同级新建 `__tests__` 来写编写单元测试。写完之后,记得在分类目录下的 `function-map` 文件中添加公式算法和函数名映射用于注册这个函数算法。
+
+ 位置在 [packages/engine-formula/src/functions/math/function-map.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/function-map.ts)。
+
+5. 单元测试
+
+ 位置在 [packages/engine-formula/src/functions/math/sumif/\_\_tests\_\_/index.spec.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/sumif/__tests__/index.spec.ts)
+
+ 注意:
+
+ - 补充 `sheetData`, 根据公式计算的需要构建好 `cellData`, 确定 `rowCount`、`columnCount`
+ - 手动初始化公式 `new Sumif(FUNCTION_NAMES_MATH.SUMIF)`
+ - 每个测试中手动构建好公式入参,最后 `calculate` 执行即可
+ - 单个公式的测试一般用于当前单个公式的算法,如果需要测试多个公式的嵌套,可以手动嵌套,或者到 `/packages/engine-formula/src/functions/__tests__` 目录下执行嵌套的复杂公式
+
+6. 功能测试
+
+ 启动 Univer 开发模式,在界面上测试公式,预先构造好数据,
+
+ - 在任一空白单元格输入 `=sumif`,预期会有搜索提示列表弹出
+ - 确认选择 `SUMIF` 或者 输入 `=sumif(` 之后,触发公式详细介绍弹窗,仔细检查介绍页内容是否完整
+ - 选择数据范围,确认之后触发计算,检查公式计算结果是否正确
+
+### 公式实现注意事项
+
+- 任何公式的入参和出参都可以是 `A1`、`A1:B10`,调研 Excel 的时候需要把所有情况考虑到,比如 `=SIN(A1:B10)`,会展开一个正弦计算后的范围。
+
+ - 例如 `XLOOKUP` 函数,要求两个入参的行或列至少又一个大小相等,这样才能进行矩阵计算。
+ - 例如 `SUMIF` 函数,大家以为是求和,但是它是可以根据第二个参数进行展开的
+ ![sumif array](./assets/img/sumif-array.png)
+ ![sumif array result](./assets/img/sumif-array-result.png)
+ - Excel 的公式计算,越来越像 numpy,比如
+ ![numpy](./assets/img/numpy.png)
+
+- 公式的数值计算,需要使用内置的方法,尽量不要获取值自行计算。因为公式的参数可以是值、数组、引用。可以参考已有的 `sum`、`minus` 函数。
+- 精度问题,公式引入了 `big.js`,使用内置方法会调用该库,但是相比原生计算会慢接近 100 倍,所以像 `sin` 等 `js` 方法,尽量用原生实现。
+- 需要自定义计算,使用 `product` 函数,适合两个入参的计算,调用 `map` 对值自身进行迭代计算,适合对一个入参本身的值进行改变。
+
+#### 公式基础工具
+
+1. `ValueObjectFactory` 用来自动识别参数格式创建一个参数实例,范围类型的数据用 `RangeReferenceObject` 来创建参数实例
+2. 数组 `toArrayValueObject` 可以与值直接运算,得到新的数组
diff --git a/packages/sheets-formula/README.md b/packages/sheets-formula/README.md
index fce3b493b5..0ed41d7f21 100644
--- a/packages/sheets-formula/README.md
+++ b/packages/sheets-formula/README.md
@@ -5,12 +5,785 @@
## Introduction
-> Formula plugin for Univer Sheets.
+`@univerjs/sheets-formula` provides the ability to edit formulas in spreadsheets, including features such as auto-completion, formula suggestions, drop-down filling for formulas, and copy-paste functionality.
+
+:::note
+Formula calculation is one of the core functionalities of spreadsheets, and formula calculation scheduling is done in `@univerjs/sheets`.
+:::
## Usage
### Installation
```shell
-npm i @univerjs/sheets-formula
+# Using npm
+npm install @univerjs/sheets-formula
+
+# Using pnpm
+pnpm add @univerjs/sheets-formula
+```
+
+### Add formula preconditions
+
+If the officially provided formula does not meet your needs, you can expand the formula yourself. Depending on different needs, we provide multiple ways to support registering one or more custom formulas.
+
+You need to first prepare the international copywriting and algorithms required for formula prompts, and then refer to our [Contribution Guide](https://github.com/dream-num/univer/blob/dev/CONTRIBUTING.md) to run the Univer project , and then start adding formulas.
+
+### How to add formulas using Uniscript
+
+Using Uniscript scripts, you can quickly and easily register custom formulas in the current Univer instance.
+
+As shown in the following case, use `registerFunction` to register the algorithm, name, and description required by a `CUSTOMSUM` formula into the formula plug-in at one time. After execution, the formula can be used. Enter `=CUSTOMSUM` in any blank cell to see the prompt.
+
+```js
+univerAPI.registerFunction({
+ calculate: [
+ [function (...variants) {
+ let sum = 0;
+
+ for(const variant of variants){
+ sum += Number(variant) || 0;
+ }
+
+ return sum;
+ }, 'CUSTOMSUM', 'Adds its arguments'],
+ // ... more formulas
+ ]
+})
+```
+
+Use the `unregisterFunction` method to quickly unregister custom formulas
+
+```ts
+univerAPI.unregisterFunction({
+ functionNames: ['CUSTOMSUM']
+})
+```
+
+If you want to provide more complete international content and description, you can also configure the `locales` and `description` fields. As follows.
+
+```js
+const FUNCTION_NAMES_USER = {
+ CUSTOMSUM: 'CUSTOMSUM'
+}
+univerAPI.registerFunction({
+ locales:{
+ 'zhCN': {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: '将单个值、单元格引用或是区域相加,或者将三者的组合相加。',
+ abstract: '求参数的和',
+ links: [
+ {
+ title: '教学',
+ url: 'https://support.microsoft.com/zh-cn/office/sum-%E5%87%BD%E6%95%B0-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要相加的第一个数字。 该数字可以是 4 之类的数字,B6 之类的单元格引用或 B2:B8 之类的单元格范围。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '这是要相加的第二个数字。 可以按照这种方式最多指定 255 个数字。',
+ },
+ },
+ },
+ // ... more formulas
+ },
+ },
+ 'enUS':{
+ formulaCustom:{
+ CUSTOMSUM: {
+ description: `You can add individual values, cell references or ranges or a mix of all three.`,
+ abstract: `Adds its arguments`,
+ links: [
+ {
+ title: 'Instruction',
+ url: 'https://support.microsoft.com/en-us/office/sum-function-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number you want to add. The number can be like 4, a cell reference like B6, or a cell range like B2:B8.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'This is the second number you want to add. You can specify up to 255 numbers in this way.',
+ },
+ },
+ },
+ }
+ }
+ },
+ description:[
+ {
+ functionName: FUNCTION_NAMES_USER.CUSTOMSUM,
+ aliasFunctionName: 'formulaCustom.CUSTOMSUM.aliasFunctionName',
+ functionType: 15,
+ description: 'formulaCustom.CUSTOMSUM.description',
+ abstract: 'formulaCustom.CUSTOMSUM.abstract',
+ functionParameter: [
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number1.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number2.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+ // ... more formulas
+ ],
+ calculate: [
+ [function (...variants) {
+ let sum = 0;
+
+ for(const variant of variants){
+ sum += Number(variant) || 0;
+ }
+
+ return sum;
+ }, FUNCTION_NAMES_USER.CUSTOMSUM],
+ // ... more formulas
+ ]
+})
+```
+
+Note
+
+- Multiple languages can be set under `locales`. For naming rules, please refer to [LocaleType](/api/core/enums/LocaleType.html). Translations for multiple formulas can be added under `functionList`. For detailed field descriptions, please refer to the [How to add formulas in UniverFormulaEnginePlugin](./#how-to-add-formulas-in-univerformulaengineplugin) section.
+- `description` sets the description of the custom formula.
+- `calculate` writes the specific algorithm and name mapping of the calculation formula. The input parameter is the content entered by the user when using the formula, which may be a number, a string, a Boolean value, or a range, and the same format is returned.
+
+Likewise, if using the `unregisterFunction` method, it is recommended that you remove the internationalization files as well. The example below removes the Chinese and English `formulaCustom` nodes.
+
+```ts
+univerAPI.unregisterFunction({
+ localeKeys: {
+ 'zhCN': ['formulaCustom'],
+ 'enUS': ['formulaCustom'],
+ },
+ functionNames: ['CUSTOMSUM']
+})
+```
+
+Uniscript uses `@univerjs/facade` under the hood. You can also use Uniscript-like APIs directly in your project. Please refer to [Registering Function](/en-us/guides/facade/register-function).
+
+### How to add formulas when initializing Univer
+
+Follow the steps below to implement a custom formula `CUSTOMSUM`.
+
+You can create a new `custom-function.ts` file to specifically place custom formula-related modules, or write it directly before `univer` is initialized.
+
+1. Define formula name
+
+ First, give the formula a name. We require that it cannot be repeated with the name of the existing formula. The existing formula is mainly from [Office Excel](https://support.microsoft.com/en-us/office/excel-functions-by-category-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb) refer to.
+
+ We collect multiple custom formulas in an enumeration.
+
+ ```ts
+ /**
+ * function name
+ */
+ export enum FUNCTION_NAMES_USER {
+ CUSTOMSUM = "CUSTOMSUM",
+ }
+ ```
+
+2. Define internationalization
+
+ Define the international content you need. For detailed field descriptions, please refer to the [How to add formulas in UniverFormulaEnginePlugin](./#how-to-add-formulas-in-univerformulaengineplugin) section. Similarly, multiple formulas are distinguished by using the formula name as the `key` value.
+
+ ```ts
+ /**
+ *i18n
+ */
+ export const functionEnUS = {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: `You can add individual values, cell references or ranges or a mix of all three.`,
+ abstract: `Adds its arguments`,
+ links: [
+ {
+ title: 'Instruction',
+ url: 'https://support.microsoft.com/en-us/office/sum-function-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number you want to add. The number can be like 4, a cell reference like B6, or a cell range like B2:B8.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'This is the second number you want to add. You can specify up to 255 numbers in this way.',
+ },
+ },
+ },
+ },
+ };
+
+ export const functionZhCN = {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: '将单个值、单元格引用或是区域相加,或者将三者的组合相加。',
+ abstract: '求参数的和',
+ links: [
+ {
+ title: '教学',
+ url: 'https://support.microsoft.com/zh-cn/office/sum-%E5%87%BD%E6%95%B0-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要相加的第一个数字。 该数字可以是 4 之类的数字,B6 之类的单元格引用或 B2:B8 之类的单元格范围。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '这是要相加的第二个数字。 可以按照这种方式最多指定 255 个数字。',
+ },
+ },
+ },
+ },
+ };
+ ```
+
+3. Registration internationalization
+
+ Expand the internationalization content you defined in the original internationalization object.
+
+ ```ts
+ export const locales = {
+ [LocaleType.EN_US]: {
+ ...UniverSheetsEnUS,
+ ...UniverDocsUIEnUS,
+ ...UniverSheetsUIEnUS,
+ ...UniverUiEnUS,
+ ...UniverDesignEnUS,
+ ...functionEnUS,
+ },
+ [LocaleType.ZH_CN]: {
+ ...functionZhCN,
+ },
+ };
+ ```
+
+4. Definition description
+
+ The description of the formula mainly configures internationalized fields, which are used for formula search prompts, details panels, etc.
+
+ ```ts
+ import type { IFunctionInfo } from '@univerjs/engine-formula';
+ import { FunctionType } from '@univerjs/engine-formula';
+
+ /**
+ * description
+ */
+ export const FUNCTION_LIST_USER: IFunctionInfo[] = [
+ {
+ functionName: FUNCTION_NAMES_USER.CUSTOMSUM,
+ aliasFunctionName: 'formulaCustom.CUSTOMSUM.aliasFunctionName',
+ functionType: FunctionType.User,
+ description: 'formulaCustom.CUSTOMSUM.description',
+ abstract: 'formulaCustom.CUSTOMSUM.abstract',
+ functionParameter: [
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number1.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number2.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+ ];
+ ```
+
+5. Registration description
+
+ Pass in the description object you defined when registering the formula plug-in.
+
+ ```ts
+ // universal
+ univer.registerPlugin(UniverSheetsFormulaPlugin, {
+ description: FUNCTION_LIST_USER,
+ });
+ ```
+
+6. Define formula algorithm
+
+ Write specific formula calculation logic, map algorithms and formula names.
+
+ ```ts
+ import type { ArrayValueObject, BaseValueObject, IFunctionInfo } from '@univerjs/engine-formula';
+ import { BaseFunction, FunctionType, NumberValueObject } from '@univerjs/engine-formula';
+
+ /**
+ * Function algorithm
+ */
+ export class Customsum extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ let accumulatorAll: BaseValueObject = new NumberValueObject(0);
+ for (let i = 0; i < variants.length; i++) {
+ let variant = variants[i];
+
+ if (variant.isError()) {
+ return variant;
+ }
+
+ if (accumulatorAll.isError()) {
+ return accumulatorAll;
+ }
+
+ if (variant.isArray()) {
+ variant = (variant as ArrayValueObject).sum();
+ }
+
+ accumulatorAll = accumulatorAll.plus(variant as BaseValueObject);
+ }
+
+ return accumulatorAll;
+ }
+ }
+
+ // Mapping of algorithms and names
+ export const functionUser = [[Customsum, FUNCTION_NAMES_USER.CUSTOMSUM]];
+ ```
+
+7. Registration formula algorithm
+
+ Pass in the formula algorithm object you defined in `UniverFormulaEnginePlugin`.
+
+ ```ts
+ univer.registerPlugin(UniverFormulaEnginePlugin, {
+ function: functionUser,
+ });
+ ```
+
+ Please note: If `UniverFormulaEnginePlugin` is instantiated in `worker`, you need to register the formula algorithm in `UniverFormulaEnginePlugin` in `worker`, otherwise the custom formula cannot be executed.
+
+8. Test
+
+ At this point, the development of the custom formula is completed, and now it is time to test it. Enter `=CUSTOMSUM` in any blank cell and expect to get a formula prompt. Here is a [Custom Formula Demo](/playground?title=Custom%20Function) for reference.
+
+### How to add formulas in third-party plug-ins
+
+If you are developing a Univer plug-in, you can add custom formulas directly to the plug-in to facilitate code management in a plug-in repository.
+
+Our internal `UniverFormulaEnginePlugin` plug-in provides a `function.service` specifically for registering formula descriptions and algorithms.
+
+First refer to [Custom Plugin](/en-us/guides/extend/write-a-plugin/) to create a new plug-in, and then you can start adding custom formulas.
+
+1. Create a new `custom-function.ts` file in the `common` file and write all the basic modules required for the formula.
+
+ ```ts
+ import type { ArrayValueObject, BaseValueObject, IFunctionInfo } from '@univerjs/engine-formula';
+ import { BaseFunction, FunctionType, NumberValueObject } from '@univerjs/engine-formula';
+
+ /**
+ * function name
+ */
+ export enum FUNCTION_NAMES_USER {
+ CUSTOMSUM = 'CUSTOMSUM',
+ }
+
+ /**
+ *i18n
+ */
+ export const functionEnUS = {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: `You can add individual values, cell references or ranges or a mix of all three.`,
+ abstract: `Adds its arguments`,
+ links: [
+ {
+ title: 'Instruction',
+ url: 'https://support.microsoft.com/en-us/office/sum-function-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number you want to add. The number can be like 4, a cell reference like B6, or a cell range like B2:B8.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'This is the second number you want to add. You can specify up to 255 numbers in this way.',
+ },
+ },
+ },
+ },
+ };
+
+ export const functionZhCN = {
+ formulaCustom: {
+ CUSTOMSUM: {
+ description: '将单个值、单元格引用或是区域相加,或者将三者的组合相加。',
+ abstract: '求参数的和',
+ links: [
+ {
+ title: '教学',
+ url: 'https://support.microsoft.com/zh-cn/office/sum-%E5%87%BD%E6%95%B0-043e1c7d-7726-4e80-8f32-07b23e057f89',
+ },
+ ],
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要相加的第一个数字。 该数字可以是 4 之类的数字,B6 之类的单元格引用或 B2:B8 之类的单元格范围。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '这是要相加的第二个数字。 可以按照这种方式最多指定 255 个数字。',
+ },
+ },
+ },
+ },
+ };
+
+ /**
+ * description
+ */
+ export const FUNCTION_LIST_USER: IFunctionInfo[] = [
+ {
+ functionName: FUNCTION_NAMES_USER.CUSTOMSUM,
+ aliasFunctionName: 'formulaCustom.CUSTOMSUM.aliasFunctionName',
+ functionType: FunctionType.User,
+ description: 'formulaCustom.CUSTOMSUM.description',
+ abstract: 'formulaCustom.CUSTOMSUM.abstract',
+ functionParameter: [
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number1.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formulaCustom.CUSTOMSUM.functionParameter.number2.name',
+ detail: 'formulaCustom.CUSTOMSUM.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+ ];
+
+ /**
+ * Function algorithm
+ */
+ export class Customsum extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ let accumulatorAll: BaseValueObject = new NumberValueObject(0);
+ for (let i = 0; i < variants.length; i++) {
+ let variant = variants[i];
+
+ if (variant.isError()) {
+ return variant;
+ }
+
+ if (accumulatorAll.isError()) {
+ return accumulatorAll;
+ }
+
+ if (variant.isArray()) {
+ variant = (variant as ArrayValueObject).sum();
+ }
+
+ accumulatorAll = accumulatorAll.plus(variant as BaseValueObject);
+ }
+
+ return accumulatorAll;
+ }
+ }
+
+ export const functionUser = [[Customsum, FUNCTION_NAMES_USER.CUSTOMSUM]];
+ ```
+
+2. Create a new `custom-description.controller.ts` under the `controllers` folder to register formula internationalization content and description.
+
+ ```ts
+ import { Disposable, LifecycleStages, LocaleService, OnLifecycle } from '@univerjs/core';
+ import { Inject } from '@wendellhu/redi';
+
+ import { FUNCTION_LIST_USER, functionEnUS, functionZhCN } from '../common/custom-function';
+ import { IDescriptionService } from '../services/description.service';
+
+ @OnLifecycle(LifecycleStages.Ready, CustomDescriptionController)
+ export class CustomDescriptionController extends Disposable {
+ constructor(
+ @IDescriptionService private readonly _descriptionService: IDescriptionService,
+ @Inject(LocaleService) private readonly _localeService: LocaleService
+ ) {
+ super();
+
+ this._initialize();
+ }
+
+ private _initialize(): void {
+ this._registerLocales();
+ this._registerCustomDescriptions();
+ }
+
+ private _registerLocales() {
+ this._localeService.load({
+ zhCN: functionZhCN,
+ enUS: functionEnUS,
+ });
+ }
+
+ private _registerCustomDescriptions() {
+ this._descriptionService.registerDescription(FUNCTION_LIST_USER);
+ }
+ }
+ ```
+
+3. Create a new `custom-function.controller.ts` under the `controllers` folder to register formula algorithms.
+
+ ```ts
+ import { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';
+ import type { BaseFunction, IFunctionNames } from '@univerjs/engine-formula';
+ import { IFunctionService } from '@univerjs/engine-formula';
+ import { type Ctor } from '@wendellhu/redi';
+
+ import { functionUser } from '../common/custom-function';
+
+ @OnLifecycle(LifecycleStages.Ready, CustomFunctionController)
+ export class CustomFunctionController extends Disposable {
+ constructor(@IFunctionService private readonly _functionService: IFunctionService) {
+ super();
+
+ this._initialize();
+ }
+
+ private _initialize(): void {
+ this._registerCustomFunctions();
+ }
+
+ private _registerCustomFunctions() {
+ const functions: BaseFunction[] = [...functionUser].map((registerObject) => {
+ const Func = registerObject[0] as Ctor<BaseFunction>;
+ const name = registerObject[1] as IFunctionNames;
+
+ return new Func(name);
+ });
+
+ this._functionService.registerExecutors(...functions);
+ }
+ }
+ ```
+
+4. In the plug-in entry file `plugin.ts`, register `custom-description.controller.ts` and `custom-function.controller.ts` into the DI system.
+
+ ```ts
+ initialize(): void {
+ // ... other logic
+
+ const dependencies: Dependency[] = [
+ // ... other modules
+ [CustomFunctionController],
+ [CustomDescriptionController],
+ ];
+
+ dependencies.forEach((dependency) => this._injector.add(dependency));
+ }
+ ```
+
+ Start Univer and enter `=CUSTOMSUM` in any blank cell to test this newly added formula.
+
+Please note: If `UniverFormulaEnginePlugin` is instantiated in `worker`, you need to register the formula algorithm in `worker`, otherwise the custom formula cannot be executed.
+In addition to registering through the `UniverFormulaEnginePlugin` configuration, the formula algorithm module can also be separately packaged as a plug-in for registration.
+
+First of all, there is no need to register `CustomFunctionController` in `plugin.ts`. Create a new `custom-function-plugin.ts` in the same directory, specifically for registering `CustomFunctionController`.
+
+```ts
+import { Plugin, PluginType } from '@univerjs/core';
+import type { Dependency } from '@wendellhu/redi';
+import { Inject, Injector } from '@wendellhu/redi';
+
+import { FORMULA_UI_PLUGIN_NAME } from './common/plugin-name';
+import { CustomFunctionController } from './controllers/custom-function.controller';
+
+export class UniverSheetsCustomFunctionPlugin extends Plugin {
+ static override type = PluginType.Sheet;
+
+ constructor(@Inject(Injector) override readonly _injector: Injector) {
+ super(FORMULA_UI_PLUGIN_NAME);
+ }
+
+ initialize(): void {
+ const dependencies: Dependency[] = [[CustomFunctionController]];
+
+ dependencies.forEach((dependency) => this._injector.add(dependency));
+ }
+
+ override onReady(): void {
+ this.initialize();
+ }
+}
```
+
+Then export it in `index.ts`
+
+```ts
+export { UniverSheetsFormulaPlugin } from './formula-ui-plugin';
+```
+
+Finally, your `worker` entry initializes the plugin.
+
+```ts
+import { UniverSheetsCustomFunctionPlugin } from '@univerjs/sheets-formula';
+
+// ...initialize other plugins
+univer.registerPlugin(UniverSheetsCustomFunctionPlugin);
+```
+
+This way you can register the formula in `worker`.
+
+### How to add formulas in UniverFormulaEnginePlugin
+
+#### Reference Documentation
+
+[Office Excel functions (by category)](https://support.microsoft.com/en-us/office/excel-functions-by-category-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb)
+
+#### Categories
+
+Detailed API reference [FunctionType](/api/engine-formula/enums/FunctionType.html)
+
+- Financial
+- Date
+- Math
+- Statistical
+- Lookup
+- Database
+- Text
+- Logical
+- Information
+- Engineering
+- Cube
+- Compatibility
+- Web
+- Array
+- Univer
+- User
+
+#### Requirements
+
+To implement a formula, you need to add formula description, internationalization, and formula algorithm. Take the `SUMIF` function as an example for reference.
+
+1. Add Function Name
+
+ Location: [packages/engine-formula/src/functions/math/function-names.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/function-names.ts).
+
+ Each category has a folder containing a `function-names` file to manage all function names in that category. Add the function name, which will be used in the `sheets-formula` plugin.
+
+ Note that a function in Excel may belong to multiple categories. For example, `FLOOR` appears in Compatibility and Math Functions, and we classify it under the Math category. Other functions are treated similarly, based on the exact classification.
+
+ > Most Excel functions have already written function names. New functions can be added at the end
+
+2. Internationalization Files
+
+ Location: [packages/sheets-formula/src/locale/function-list/math/en-US.ts](https://github.com/dream-num/univer/blob/dev/packages/sheets-formula/src/locale/function-list/math/en-US.ts).
+
+ Internationalization is organized by category, with a file for each category. Refer to the Office function category page for a brief overview.
+ ![office excel](./assets/img/office-excel.png)
+
+ Refer to the Office function details page for function descriptions and parameter descriptions.
+ ![sumif](./assets/img/sumif.png)
+
+ Most function names already have basic description, abstract, links, and parameter structures. It is recommended to modify them based on this foundation. If a function is not present, add it to the end.
+
+ Requirements:
+
+ - Use the English names of function parameters as the `key` for translation, e.g., `SUMIF`. Generally, do not modify unless there is an error.
+ - Extract the `description` from the content, as some Excel descriptions are lengthy and need simplification.
+ - `abstract` and `links` generally do not need modification.
+ - `aliasFunctionName` is optional; most formulas do not need to be filled (or can be set for aliases in specific countries). Currently, there is no documentation for formula aliases. Currently I have found a function translation plug-in that may provide similar functions [Excel Functions Translator](https://support.microsoft.com/en-us/office/excel-functions-translator-f262d0c0-991c-485b-89b6-32cc8d326889)
+ - `functionParameter` needs a name for each parameter. We recommend varying names based on the parameter's meaning, e.g., use `number` for a numeric parameter (if there is only one) or `number1`, `number2` for multiple numeric parameters. Use `range` for a range, `criteria` for conditions, and `sum_range` for the sum range (separated by `_` for multiple words).
+ - Some Chinese translations in the Office function documentation are machine-translated and may be unclear. Modify as needed. For example, `单元格参考` (Cell Reference) should be translated as `单元格引用`. Numeric type parameters are uniformly translated as: `数值`.
+ - Do not end `abstract` with a period (used in the search list when users input cells), but end `description` and `detail` with a period (used in descriptions).
+ - Capitalize the first letter of English sentences.
+ - Ensure that all existing internationalization files are filled. Currently, there are only Chinese, English, and Japanese translations (languages can be switched at the bottom of the Excel introduction page).
+
+3. Formula Descriptions
+
+ `SUMIF` belongs to the `math` category, and the description is in [packages/sheets-formula/src/services/function-list/math.ts](https://github.com/dream-num/univer/blob/dev/packages/sheets-formula/src/services/function-list/math.ts), which manages all functions in the `math` category.
+
+ Most function names already have basic description structure. It is recommended to modify them based on this foundation. If a function is not present, add it to the end.
+
+ Requirements:
+
+ - Add the formula to the `FUNCTION_LIST_MATH` array. It is recommended to keep the order consistent with the internationalization file for easy management and retrieval.
+ - Reference the previously defined `FUNCTION_NAMES_MATH` enum for the `functionName`.
+ - `aliasFunctionName` is also optional; if there are no aliases in the internationalization file, you do not need to add them here.
+ - Pay attention to the correspondence between internationalization fields and function and parameter names.
+ - Modify function parameter information, including the `example` parameter example (e.g., for a range, use `"A1:A20"`; for conditions, use `">5"`), the `require` parameter (1 for required, 0 for optional), and the `repeat` parameter (1 for allowed, 0 for not allowed). For detailed information, refer to the interface [IFunctionParam](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/basics/function.ts).
+
+4. Formula Algorithm
+
+ Location: [packages/engine-formula/src/functions/math/sumif/index.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/sumif/index.ts).
+
+ Create a new folder for the formula under the current formula category, with one folder per formula. Then create an `index.ts` file to write the formula algorithm. Use camel case for the formula `class` name, considering the formula as one word. If a formula contains `_` or `.`, treat it as two words, such as:
+
+ - `SUMIF` => `Sumif`
+ - `NETWORKDAYS.INTL` => `Networkdays_Intl`
+ - `ARRAY_CONSTRAIN` => `Array_Constrain`
+
+ Create a `__tests__` folder at the same level to write unit tests. After writing, remember to add the formula algorithm and function name mapping in the `function-map` file in the category directory to register the formula algorithm.
+
+ Location: [packages/engine-formula/src/functions/math/function-map.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/function-map.ts).
+
+5. Unit Tests
+
+ Location: [packages/engine-formula/src/functions/math/sumif/\_\_tests\_\_/index.spec.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/sumif/__tests__/index.spec.ts)
+
+ Note:
+
+ - Supplement `sheetData` according to the formula's calculation needs, construct `cellData` based on the calculated data, and determine `rowCount` and `columnCount`.
+ - Manually initialize the formula with `new Sumif(FUNCTION_NAMES_MATH.SUMIF)`.
+ - Manually build the formula parameters for each test, and execute `calculate` at the end.
+ - Single formula tests are generally used for testing the algorithm of the current formula. If testing nested formulas with multiple formulas is needed, manually nest them or go to the `/packages/engine-formula/src/functions/__tests__` directory to execute complex nested formulas.
+
+6. Functional Tests
+
+ Start Univer in development mode, test formulas on the interface, and preconstruct data.
+
+ - In any blank cell, enter `=sumif`. Expect a search prompt list to appear.
+ - After selecting `SUMIF` or entering `=sumif(`, trigger the formula details popup and carefully check the contents.
+ - Select the data range, trigger the calculation, and check if the formula calculation result is correct.
+
+#### Considerations for Formula Implementation
+
+- Any formula's input and output can be `A1`, `A1:B10`, etc. When researching Excel, consider all cases, such as `=SIN(A1:B10)`, which expands to the calculated range.
+ - For example, the `XLOOKUP` function requires at least one of the rows or columns of its two inputs to be of equal size for matrix calculation.
+ - For example, the `SUMIF` function, although commonly used for summation, can expand based on the second parameter.
+ ![sumif array](./assets/img/sumif-array.png)
+ ![sumif array result](./assets/img/sumif-array-result.png)
+ - Excel formula calculation is becoming more like numpy, for example:
+ ![numpy](./assets/img/numpy.png)
+- For numerical calculations in formulas, use built-in methods and try to avoid obtaining values for manual calculation. Because formula parameters can be values, arrays, or references. You can refer to existing `sum` and `minus` functions.
+- Precision issues: The formula introduces `big.js`, and using built-in methods will call this library. However, it is nearly 100 times slower than native calculations. Therefore, for methods like `sin`, it is advisable to use native implementations.
+- For custom calculations, use the `product` function, suitable for calculating two input parameters. Call `map` to iterate over the values for changes to a parameter's own values.
+
+#### Formula Basic Tools
+
+1. `ValueObjectFactory` is used to automatically recognize parameter formats and create a parameter instance. Use `RangeReferenceObject` to create parameter instances for range-type data.
+2. The array `toArrayValueObject` can be operated directly with values to get a new array.
diff --git a/packages/sheets-numfmt/README-zh.md b/packages/sheets-numfmt/README-zh.md
new file mode 100644
index 0000000000..f75506728b
--- /dev/null
+++ b/packages/sheets-numfmt/README-zh.md
@@ -0,0 +1,47 @@
+# @univerjs/sheets-numfmt
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-numfmt)](https://npmjs.org/package/@univerjs/sheets-numfmt)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-numfmt)](https://img.shields.io/npm/l/@univerjs/sheets-numfmt)
+
+## 简介
+
+提供数字格式的编辑/渲染能力,例如编辑面板、工具栏按钮、实时预览、行列变化等等。
+
+:::note
+数字格式是电子表格的核心功能之一,因此数字格式的解析处理是在 `@univerjs/sheets` 中进行的。
+:::
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/sheets-numfmt
+
+# 使用 pnpm
+pnpm add @univerjs/sheets-numfmt
+```
+
+### 使用介绍
+在你的入口文件处,引用 `@univerjs/sheets-numfmt`.
+```ts
+import { LocaleType, LogLevel, Univer } from '@univerjs/core';
+import { defaultTheme } from '@univerjs/design';
+import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
+
+// univer
+const univer = new Univer({
+ theme: defaultTheme,
+ locale: LocaleType.ZH_CN,
+ locales,
+ logLevel: LogLevel.VERBOSE,
+});
+
+// ... 其他插件注册
+
+univer.registerPlugin(UniverSheetsNumfmtPlugin);
+```
+:::note
+如果你需要导出快照支持导出数据格式,需要额外新增[一部分代码](/guides/extend/model/#本地化快照方案)
+:::
diff --git a/packages/sheets-numfmt/README.md b/packages/sheets-numfmt/README.md
index f555ab13fe..1a7a847011 100644
--- a/packages/sheets-numfmt/README.md
+++ b/packages/sheets-numfmt/README.md
@@ -5,12 +5,44 @@
## Introduction
-> Numfmt plugin for Univer Sheets.
+Providing editing/rendering capabilities around `number format`, such as edit panels, toolbar buttons, real-time previews, row/column variations, etc.
+
+:::Note
+Numerical format is one of the core functions of electronic spreadsheets, and therefore, parsing and handling of numerical format is done within `@univerjs/sheets`.
+:::
## Usage
### Installation
```shell
-npm i @univerjs/sheets-numfmt
+# Using npm
+npm install @univerjs/sheets-numfmt
+
+# Using pnpm
+pnpm add @univerjs/sheets-numfmt
+```
+
+### How to use
+Import `@univerjs/sheets-numfmt` at the entrance .
+```ts
+import { LocaleType, LogLevel, Univer } from '@univerjs/core';
+import { defaultTheme } from '@univerjs/design';
+import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
+
+// univer
+const univer = new Univer({
+ theme: defaultTheme,
+ locale: LocaleType.ZH_CN,
+ locales,
+ logLevel: LogLevel.VERBOSE,
+});
+
+// ... Other plug-ins are registered
+
+univer.registerPlugin(UniverSheetsNumfmtPlugin);
```
+
+:::note
+If you need to export the snapshot to support the export data format, you need to add [some additional code](/)
+:::
diff --git a/packages/sheets-ui/README-zh.md b/packages/sheets-ui/README-zh.md
new file mode 100644
index 0000000000..f046509adf
--- /dev/null
+++ b/packages/sheets-ui/README-zh.md
@@ -0,0 +1,25 @@
+# @univerjs/sheets-ui
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-ui)](https://npmjs.org/package/@univerjs/sheets-ui)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-ui)](https://img.shields.io/npm/l/@univerjs/sheets-ui)
+
+## 简介
+
+`@univerjs/sheets-ui` 提供了 sheet 的 UI,包括:
+
+* sheet 基础功能的快捷键
+* 复制粘贴服务,业务可以调用复制粘贴服务提供的方法来自定义某项功能的复制粘贴行为
+* 下拉填充服务,业务可以调用下拉填充服务提供的方法来自定义某项功能的下拉填充行为
+* 单元格编辑器服务
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/sheets-ui
+
+# 使用 pnpm
+pnpm add @univerjs/sheets-ui
+```
diff --git a/packages/sheets-ui/README.md b/packages/sheets-ui/README.md
index b890a566eb..09a497962c 100644
--- a/packages/sheets-ui/README.md
+++ b/packages/sheets-ui/README.md
@@ -5,12 +5,22 @@
## Introduction
-> UI plugin for Univer Sheets.
+The `@univerjs/sheets-ui` library provides the user interface (UI) for sheets, including:
+
+* Keyboard shortcuts and menu items for basic sheet functions
+* Copy-paste service, allowing customization of copy-paste behavior for specific features via the provided methods
+* Autofill service, enabling customization of autofill behavior for specific features via the provided methods
+* Cell editor and formula editor
+* Rendering spreadsheets in canvas
## Usage
### Installation
```shell
-npm i @univerjs/sheets-ui
+# Using npm
+npm install @univerjs/sheets-ui
+
+# Using pnpm
+pnpm add @univerjs/sheets-ui
```
diff --git a/packages/sheets-zen-editor/README-zh.md b/packages/sheets-zen-editor/README-zh.md
new file mode 100644
index 0000000000..231af8f183
--- /dev/null
+++ b/packages/sheets-zen-editor/README-zh.md
@@ -0,0 +1,20 @@
+# @univerjs/sheets-zen-editor
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-zen-editor)](https://npmjs.org/packages/@univerjs/sheets-zen-editor)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-zen-editor)](https://img.shields.io/npm/l/@univerjs/sheets-zen-editor)
+
+## 简介
+
+`@univerjs/sheets-zen-editor` 为 sheets 的每个 cell 提供了沉浸式编辑的体验。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/sheets-zen-editor
+
+# 使用 pnpm
+pnpm add @univerjs/sheets-zen-editor
+```
diff --git a/packages/sheets-zen-editor/README.md b/packages/sheets-zen-editor/README.md
index 78c169193c..54cce89c6b 100644
--- a/packages/sheets-zen-editor/README.md
+++ b/packages/sheets-zen-editor/README.md
@@ -5,12 +5,16 @@
## Introduction
-> Zen Editor plugin for Univer Sheets. This plugin allows you to edit your sheets in a zen mode.
+`@univerjs/sheets-zen-mode-editor` enhances the immersive editing experience for cells in sheets.
## Usage
### Installation
```shell
-npm i @univerjs/sheets-zen-editor
+# Using npm
+npm install @univerjs/sheets-zen-editor
+
+# Using pnpm
+pnpm add @univerjs/sheets-zen-editor
```
diff --git a/packages/sheets/README-zh.md b/packages/sheets/README-zh.md
new file mode 100644
index 0000000000..3bae795985
--- /dev/null
+++ b/packages/sheets/README-zh.md
@@ -0,0 +1,44 @@
+# @univerjs/sheets
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets)](https://npmjs.org/package/@univerjs/sheets)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets)](https://img.shields.io/npm/l/@univerjs/sheets)
+
+## 简介
+
+`@univerjs/sheets` 承载 sheet 的主要(基础)业务逻辑,base-sheets 被设计为 UI 无关,因此也可以运行在 Node.js 环境中,借此可以实现协同编辑等功能。
+
+`@univerjs/sheets` 为 Univer Sheet 提供了以下能力:
+
+* 提供核心能力,例如数字格式、选区管理、权限等等
+* 更改电子表格数据的 commands / mutations
+* 公式核心能力
+* 数字格式核心能力
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/sheets
+
+# 使用 pnpm
+pnpm add @univerjs/sheets
+```
+
+### `SheetInterceptorService`
+
+`SheetInterceptorService` 是 `@univerjs/sheets` 提供的一个较为特殊的服务,它允许上层业务修改从 Worksheet 中获取单元格数据、获取行列隐藏信息等操作的结果,以及在特定的 command 执行时补充 mutation 或者 operation。这个服务的主要目的是为了实现一些特殊的功能,例如:
+
+1. sheet 公式
+2. sheet 条件格式
+3. sheet 数据验证
+4. sheet 数据透视表
+
+具体的使用方法请参考 API 文档。
+
+#### **何时使用 `SheetInterceptorService`,何时不要使用?**
+
+当各个功能需要操作同一块数据或者状态,但是它们之前并没有明确的依赖关系时使用 `SheetInterceptorService`,例如:数据透视表、公式、条件格式、数据验证、单元格原始数据都可能影响其他功能对单元格内容的取值结果,但是它们之间并没有明确的依赖关系,因此使用 `SheetInterceptorService` 来实现这些功能是比较合适的。
+
+如果一个功能明确地依赖其他功能,例如公式需要在下拉填充或复制粘贴功能被调用时做一些操作,那么公式模块应该直接依赖下拉填充和复制粘贴模块,而不是通过 `SheetInterceptorService` 来实现。
diff --git a/packages/sheets/README.md b/packages/sheets/README.md
index f02740af86..5fb0fab9d2 100644
--- a/packages/sheets/README.md
+++ b/packages/sheets/README.md
@@ -1,13 +1,44 @@
# @univerjs/sheets
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets)](https://npmjs.org/package/@univerjs/sheets)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets)](https://img.shields.io/npm/l/@univerjs/sheets)
+
## Introduction
-> Core library for Univer Sheets.
+`@univerjs/sheets` serves as the foundation for the core business logic of spreadsheets, with base-sheets designed to be UI-agnostic, allowing for functionality such as collaborative editing to be implemented in a Node.js environment.
+
+`@univerjs/sheets` provides the following capabilities for Univer Sheet:
+
+* Core functionality, including numerical formatting, selection management, permissions, etc.
+* Commands/mutations for modifying spreadsheet data
+* Formula core functionality
+* Core numerical formatting functionality
## Usage
### Installation
```shell
-npm i @univerjs/sheets
+# Using npm
+npm install @univerjs/sheets
+
+# Using pnpm
+pnpm add @univerjs/sheets
```
+
+### `SheetInterceptorService`
+
+`SheetInterceptorService` is a more specialized service provided by `@univerjs/sheets` that allows higher-level business to modify the results of operations such as obtaining cell data, retrieving row/column hiding information from a Worksheet, and supplementing mutations or operations at specific command executions. This service's primary goal is to enable specific functionalities, including:
+
+1. Sheet formulas
+2. Sheet conditional formatting
+3. Sheet data validation
+4. Sheet pivot tables
+
+For detailed usage, please refer to the API documentation.
+
+#### When to use `SheetInterceptorService` and when not to?
+
+Use `SheetInterceptorService` when multiple features need to operate on the same data or state, but do not have a clear dependency relationship. For example: pivot tables, formulas, conditional formatting, data validation, and raw cell data can all affect how other features retrieve a cell's value, but they do not depend on each other. In this case, using `SheetInterceptorService` to implement these features is appropriate.
+
+However, if one feature relies explicitly on another feature, such as a formula needing to perform certain actions when the fill down or copy-paste functions are called, the formula module should directly depend on the fill down and copy-paste modules, instead of using `SheetInterceptorService` for implementation.
diff --git a/packages/slides-ui/README-zh.md b/packages/slides-ui/README-zh.md
new file mode 100644
index 0000000000..228c94eecc
--- /dev/null
+++ b/packages/slides-ui/README-zh.md
@@ -0,0 +1,20 @@
+# @univerjs/slides-ui
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/slides-ui)](https://npmjs.org/package/@univerjs/slides-ui)
+[![license](https://img.shields.io/npm/l/@univerjs/slides-ui)](https://img.shields.io/npm/l/@univerjs/slides-ui)
+
+## 简介
+
+TODO: Not written yet.
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/slides-ui
+
+# 使用 pnpm
+pnpm add @univerjs/slides-ui
+```
diff --git a/packages/slides-ui/README.md b/packages/slides-ui/README.md
index cc091bc741..718eef723d 100644
--- a/packages/slides-ui/README.md
+++ b/packages/slides-ui/README.md
@@ -5,12 +5,16 @@
## Introduction
-> UI plugin for Univer Slides.
+TODO: Not written yet.
## Usage
### Installation
```shell
-npm i @univerjs/slides-ui
+# Using npm
+npm install @univerjs/slides-ui
+
+# Using pnpm
+pnpm add @univerjs/slides-ui
```
diff --git a/packages/slides/README-zh.md b/packages/slides/README-zh.md
new file mode 100644
index 0000000000..abb4b40f0e
--- /dev/null
+++ b/packages/slides/README-zh.md
@@ -0,0 +1,20 @@
+# @univerjs/slides
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/slides)](https://npmjs.org/package/@univerjs/slides)
+[![license](https://img.shields.io/npm/l/@univerjs/slides)](https://img.shields.io/npm/l/@univerjs/slides)
+
+## 简介
+
+TODO: Not written yet.
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/slides
+
+# 使用 pnpm
+pnpm add @univerjs/slides
+```
diff --git a/packages/slides/README.md b/packages/slides/README.md
index 5983a804ad..7f103670e1 100644
--- a/packages/slides/README.md
+++ b/packages/slides/README.md
@@ -5,12 +5,16 @@
## Introduction
-> Core library for Univer Slides.
+TODO: Not written yet.
## Usage
### Installation
```shell
-npm i @univerjs/slides
+# Using npm
+npm install @univerjs/slides
+
+# Using pnpm
+pnpm add @univerjs/slides
```
diff --git a/packages/ui/README-zh.md b/packages/ui/README-zh.md
new file mode 100644
index 0000000000..d3353818f5
--- /dev/null
+++ b/packages/ui/README-zh.md
@@ -0,0 +1,35 @@
+# @univerjs/ui
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/ui)](https://npmjs.org/package/@univerjs/ui)
+[![license](https://img.shields.io/npm/l/@univerjs/ui)](https://img.shields.io/npm/l/@univerjs/ui)
+
+## 简介
+
+`@univerjs/ui` 定义了基本的 UI 服务,并基于 React 提供了一套桌面端的 Workbench 实现。
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/ui
+
+# 使用 pnpm
+pnpm add @univerjs/ui
+```
+
+### UI 服务
+
+UI 服务定义了一些在客户端运行,但与特定的宿主无关(例如桌面端浏览器、移动端 webview 等)的 UI 服务。通过注入这些服务,业务功能可以在不同的宿主中调用相同的接口,而不用关心宿主的差异。
+
+这些 UI 服务包括:
+
+- 菜单服务,用于注册菜单项以及其对应的 command
+- 快捷键服务,用于注册快捷键以及其对应的 command
+- 剪贴板服务,从剪贴板读取或写入数据
+- 弹窗服务,包括 confirm 和 dialog 等
+
+### Workbench
+
+除了 UI 服务之外,`@univerjs/ui` 还基于 React 实现了工作区,包括标题栏、工具栏、正文区域、右键菜单、侧边栏等等。业务可以通过 Workbench 提供的 API 来自定义渲染内容。
diff --git a/packages/ui/README.md b/packages/ui/README.md
index 8197172419..1af287d97d 100644
--- a/packages/ui/README.md
+++ b/packages/ui/README.md
@@ -12,5 +12,24 @@
### Installation
```shell
-npm i @univerjs/ui
+# Using npm
+npm install @univerjs/ui
+
+# Using pnpm
+pnpm add @univerjs/ui
```
+
+### UI service
+
+UI services define a set of user interface services that run on the client side but are agnostic to the specific host environment (such as desktop browsers, mobile webviews, etc.). By injecting these services, business functionalities can invoke the same interfaces across different hosts without worrying about host disparities.
+
+These UI services include:
+
+- Menu service, used to register menu items and their associated commands.
+- Shortcut service, for registering keyboard shortcuts and their corresponding commands.
+- Clipboard service, to read from or write to the clipboard.
+- Popup service, which includes confirmations, dialogs, and more.
+
+### Workbench
+
+In addition to UI services, `@univerjs/ui` also implements a workspace based on React, which includes elements such as the title bar, toolbar, main content area, context menu, sidebar, and more. Businesses can customize the rendered content using the APIs provided by the Workbench.
diff --git a/packages/uniscript/README-zh.md b/packages/uniscript/README-zh.md
new file mode 100644
index 0000000000..0773cb2c6c
--- /dev/null
+++ b/packages/uniscript/README-zh.md
@@ -0,0 +1,57 @@
+# @univerjs/uniscript
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/uniscript)](https://npmjs.org/package/@univerjs/uniscript)
+[![license](https://img.shields.io/npm/l/@univerjs/uniscript)](https://img.shields.io/npm/l/@univerjs/uniscript)
+
+## 简介
+
+![](./assets//uniscript.jpeg)
+
+`@univerjs/uniscript` 提供了一个基于 TypeScript 的 DSL,可以用来操作 Univer 的数据结构和业务逻辑。
+
+用户可以在 @univerjs/uniscript 提供的代码编辑器中编写业务逻辑,以达成更加灵活的业务需求。如图所示,用户可以编写一段 Uniscript 用于从选区中读取身份证号并验证这些身份证号的合法性,把不合法的身份证号的背景标记为红色。
+
+:::caution
+Uniscript 仍在试验阶段,建议不要在生产环境中使用。你可以在[路线图](https://univer.ai/guides/roadmap/)了解 Uniscript 的迭代计划。
+:::
+
+:::tip
+Uniscript 的 DSL 实际上是一套封装 Univer 内部实现细节的 Facade API,这套 API 定义在[这里](https://univer.ai/en-us/guides/facade/)。
+:::
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/uniscript
+
+# 使用 pnpm
+pnpm add @univerjs/uniscript
+```
+
+### 获取编辑器实例
+
+@univerjs/uniscript 内部使用了 [monaco editor](https://microsoft.github.io/monaco-editor/) 作为代码编辑器,你可以通过以下方式获取编辑器实例:
+
+```ts
+const editor = univer
+ .__getInjector()
+ .get(ScriptEditorService)
+ .getEditorInstance();
+```
+
+或者在你的模块中注入 `ScriptEditorService` 以获取编辑器实例。
+
+```ts
+export class YourModule {
+ constructor(
+ @Inject(ScriptEditorService) private readonly _scriptEditorService
+ ) {}
+
+ private _getEditor() {
+ return this._scriptEditorService.getEditorInstance();
+ }
+}
+```
diff --git a/packages/uniscript/README.md b/packages/uniscript/README.md
index 9b2449e9e7..a0092e8d58 100644
--- a/packages/uniscript/README.md
+++ b/packages/uniscript/README.md
@@ -5,12 +5,50 @@
## Introduction
-> Univer uniscript package. This package add scripting feature to univer.
+![](./assets//uniscript.jpeg)
+
+`@univerjs/uniscript` uses the DSL (Domain-Specific Language) provided by `@univerjs/facade` and creates a code editor for Users to write code for operating Univer's data structures and business logic.
+
+Users can write business logic in the code editor to meet more flexible business requirements. For instance, as shown in the illustration, users can write a Uniscript to read identity card numbers from a selected area and validate their legality, and mark the background of invalid identity card numbers with red.
+
+:::caution
+The Uniscript is currently in the experimental stage, and it is not recommended to use it in production environments. You can refer to the [Roadmap](https://univer.ai/en-us/guides/roadmap/) to understand the iteration plan of Uniscript.
+:::
+
+:::tip
+Indeed, Uniscript's Domain-Specific Language (DSL) is a set of Facade APIs that encapsulate the internal implementation details of Univer. This API is defined [here](https://univer.ai/en-us/guides/facade/).
+:::
## Usage
### Installation
```shell
-npm i @univerjs/uniscript
+# Using npm
+npm install @univerjs/uniscript
+
+# Using pnpm
+pnpm add @univerjs/uniscript
+```
+
+### Get the Editor Instance
+
+The `@univerjs/uniscript` uses [Monaco Editor](https://microsoft.github.io/monaco-editor/) as its code editor. You can obtain an instance of the editor through the following method:
+
+```ts
+const editor = univer.__getInjector().get(ScriptEditorService).getEditorInstance();
+```
+
+Or inject `ScriptEditorService` into your module to obtain the editor instance.
+
+```ts
+export class YourModule {
+ constructor(
+ @Inject(ScriptEditorService) private readonly _scriptEditorService
+ ) {}
+
+ private _getEditor() {
+ return this._scriptEditorService.getEditorInstance();
+ }
+}
```
diff --git a/packages/uniscript/assets/uniscript.jpeg b/packages/uniscript/assets/uniscript.jpeg
new file mode 100644
index 0000000000..272f2309bb
Binary files /dev/null and b/packages/uniscript/assets/uniscript.jpeg differ