目录

目录会在文档正文中插入标题条目,与用于跳转的大纲面板是两个功能。在 Docs 核心配置基础上,创建文档前添加以下插件,将 UI 语言包合并到 locales 并加载样式。Docs 核心和高级预设均未包含这两个插件。

Shell
pnpm add @univerjs/docs-toc @univerjs/docs-toc-ui
TypeScript
import { UniverDocsTocPlugin } from '@univerjs/docs-toc'import { UniverDocsTocUIPlugin } from '@univerjs/docs-toc-ui'import FeatureLocale from '@univerjs/docs-toc-ui/locale/zh-CN'import { LocaleType } from '@univerjs/core'import '@univerjs/docs-toc-ui/lib/index.css'univerAPI.loadLocales(LocaleType.ZH_CN, FeatureLocale)univer.registerPlugin(UniverDocsTocPlugin)univer.registerPlugin(UniverDocsTocUIPlugin)

插入与更新

先将光标放到文档中再插入。UI 支持插入、更新整个目录、仅更新页码和删除。不传 rangeId 时,更新操作针对当前选区所在的目录。

TypeScript
import { InsertTableOfContentsCommand, UpdateTableOfContentsCommand } from '@univerjs/docs-toc'await univerAPI.executeCommand(InsertTableOfContentsCommand.id, {  levels: 3,  showPageNumbers: true,  rightAlignPageNumbers: true,})await univerAPI.executeCommand(UpdateTableOfContentsCommand.id, { mode: 'entireTable' })

更新器计算基于大纲级别的目录指令(\o)。导入的其他 Word 开关会保留在 FIELD 元数据中,但并非全部参与计算。完整参数见命令参考

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.