目錄

目錄將標題條目寫入文件正文,與用於跳轉的大綱面板是兩個不同的功能。需要在 Docs 核心配置的基礎上,於建立文件之前加入下面兩個外掛,將 UI 語言套件合併到 locales,並載入樣式表。Docs 核心和高階預設均未包含這兩個外掛。

目錄功能適用於傳統文件。在現代文件中,Univer 會隱藏目錄選單。

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-TW'import { LocaleType } from '@univerjs/core'import '@univerjs/docs-toc-ui/lib/index.css'univerAPI.loadLocales(LocaleType.ZH_TW, 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.