API 参考

Document

本 API 页面目前提供英文正文。代码签名与标识符不随界面语言变化。
Packages@univerjs/docs, @univerjs/docs-ui, @univerjs/docs-drawing, @univerjs/docs-thread-comment

The facade classes for Univer Docs documents and paragraphs.

These classes should not be instantiated directly. When using the Facade API, use univerAPI.createDocument(data) to create a document and get its facade wrapper. When working with the underlying univer instance directly, use univer.createUnit(UniverInstanceType.UNIVER_DOC, data).

Overview

@univerjs/docs

ClassMethodDescription
univerAPIcreateDocumentCreate a document and return its facade wrapper.
univerAPIgetActiveDocumentGet the currently focused document.
univerAPIgetDocumentGet a document facade wrapper by document id.
FDocumentgetDocumentDataModelGet the document data model.
FDocumentgetBodyGet the main body or a header/footer body by segment id.
FDocumentdisposeDispose the facade wrapper.
FDocumentgetIdGet the document id.
FDocumentgetPermission, getEntityPermissionAccess command-backed unit and object permissions.
FDocumentgetNameGet the document name.
FDocumentsetNameUpdate the document name.
FDocumentgetDocumentFlavorGet the document flavor.
FDocumentisTraditionalCheck whether the document uses traditional pagination.
FDocumentisModernCheck whether the document uses the modern document flavor.
FDocumentsaveSave and return the document snapshot data.
FDocumentundoUndo the last operation in the focused document.
FDocumentredoRedo the last undone operation in the focused document.
FDocumentensurePageHeaderEnsure that a page header segment exists.
FDocumentensurePageFooterEnsure that a page footer segment exists.
FDocumentgetHeaderFooterOptions, setHeaderFooterOptionsRead or update document-level header and footer settings.
FDocumentinsertTextInsert plain text at a body offset.
FDocumentgetTextRangeCreate a fixed text-range facade.
FDocumentgetSections, getSection, getSectionAtResolve traditional document sections.
FDocumentinsertSectionBreak, insertColumnBreak, insertHorizontalRuleInsert structural document elements.
FDocumentgetParagraphsGet all paragraph wrappers for a body segment.
FDocumentgetParagraphGet a paragraph wrapper by paragraph id.
FDocumentfindParagraphByTextFind the first paragraph containing text.
FDocumentfindParagraphsFind paragraphs by text, paragraph id, or segment id.
FDocumentinsertParagraphInsert a plain-text paragraph at an index.
FDocumentappendParagraphAppend a plain-text paragraph to the body.
FDocumentdeleteRangeDelete a text range from the body.
FDocumentParagraphgetSegmentIdGet the paragraph segment id.
FDocumentParagraphgetIdGet the stable paragraph id.
FDocumentParagraphgetPermissionAccess the paragraph's effective edit permission.
FDocumentParagraphgetInfoGet resolved paragraph metadata.
FDocumentParagraphgetRangeGet the paragraph text range.
FDocumentParagraphgetTextRange, findText, findAllTextCreate or find fixed text ranges in the paragraph.
FDocumentParagraphgetTextGet the paragraph plain text.
FDocumentParagraphsetTextReplace the paragraph plain text.
FDocumentParagraphappendTextAppend plain text before the paragraph break.
FDocumentParagraphsetStyleApply paragraph or text style.
FDocumentParagraphisListItemCheck whether the paragraph has list metadata.
FDocumentParagraphisTaskCheck whether the paragraph is a checklist item.
FDocumentParagraphsetTaskCheckedSet checklist state for a task paragraph.
FDocumentParagraphremoveRemove the paragraph.

@univerjs/docs-thread-comment

ClassMethodsDescription
FDocumentTextRangecreateCommentAsync, getComments, listCommentsAsyncCreate and query comments anchored to a fixed text range.

@univerjs/docs-ui

ClassMethodDescription
FDocumentsetSelectionSet the rendered selection range in a document.

@univerjs/docs-drawing

ClassMethodDescription
FDocumentinsertImageInsert an image into the document.
FDocumentgetImageGet an image by drawing id.
FDocumentgetImagesGet all document images in drawing order.
FDocumentImagegetId, getSource, getSize, getAngleRead image identity, source, and transform.
FDocumentImagesetSize, setRotate, setPositionH, setPositionVUpdate image geometry.
FDocumentImagesetWrappingStyle, setForward, setBackward, setFront, setBack, removeUpdate layout or remove the image.

Permissions

Unit permissions expose Edit, Copy, Export, and Comment points. Paragraph and section permissions use the object's stable ID and apply the document-level permission as a ceiling.

TypeScript
import { UnitAction } from '@univerjs/protocol'const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active document')await document.getPermission().setPoint(UnitAction.Copy, false)await document.getParagraphs()[0]?.getPermission().setReadOnly()console.log(document.getPermission().canEdit())

Use getEntityPermission(segmentId, entityType, entityId) for a stable document object that does not have its own Facade wrapper.

Text-range comments

TypeScript
import '@univerjs/docs-thread-comment/facade'const range = univerAPI.getActiveDocument()?.getTextRange(0, 12)await range?.createCommentAsync('Verify this introduction.', { id: 'review-intro' })const comments = await range?.listCommentsAsync()

getComments() reads locally loaded overlapping threads. listCommentsAsync() first synchronizes known threads through the configured datasource.

Structure and text ranges

Traditional documents expose stable section facades. Modern documents use column groups instead; getSections() returns an empty array for them.

TypeScript
// FDocumentgetDocumentFlavor(): DocumentFlavorisTraditional(): booleangetHeaderFooterOptions(): IHeaderFooterPropssetHeaderFooterOptions(options: IHeaderFooterProps): booleangetTextRange(startOffset: number, endOffset: number, segmentId?: string): FDocumentTextRangegetSections(): FDocumentSection[]getSection(index: number): FDocumentSection | nullgetSectionAt(offset: number): FDocumentSection | nullinsertSectionBreak(offset: number, options?: IFDocumentInsertSectionBreakOptions): FDocumentSection | nullinsertColumnBreak(offset: number): booleaninsertHorizontalRule(offset: number, border?: IParagraphBorder, segmentId?: string): FDocumentParagraph | null// FDocumentParagraphgetId(): stringgetTextRange(): FDocumentTextRangefindText(text: string, options?: IFDocumentFindTextOptions): FDocumentTextRange | nullfindAllText(text: string, options?: Omit<IFDocumentFindTextOptions, 'occurrence'>): FDocumentTextRange[]// FDocumentTextRangegetRange(): IFDocumentTextRangegetText(): stringgetExplicitTextStyleRuns(): IFDocumentTextStyleRun[]getCommonExplicitTextStyle(): ITextStyledescribe(): IFDocumentTextRangeDescriptionsetTextStyle(style: ITextStyle): booleansetText(text: string): boolean

FDocumentSection supports column layout, section types, page setup, section-specific headers and footers, and removal:

TypeScript
getId(): stringgetIndex(): numbergetConfig(): ISectionBreakgetRange(): IFDocumentTextRangegetColumns(): ISectionColumnProperties[]describe(): IFDocumentSectionDescriptionsetColumns(columnCount: number, options?: IFDocumentSectionColumnOptions): booleansetColumnProperties(columns: ISectionColumnProperties[], separator?: ColumnSeparatorType): booleansetSectionType(sectionType: SectionType): booleangetPageSetup(): FDocumentSectionPageSetupgetEffectivePageSetup(): IEffectiveSectionPageSetupsetPageSetup(pageSetup: FDocumentSectionPageSetup): booleanensureHeader(variant?: SectionHeaderFooterVariant): stringensureFooter(variant?: SectionHeaderFooterVariant): stringgetHeaderId(variant?: SectionHeaderFooterVariant): string | nullgetFooterId(variant?: SectionHeaderFooterVariant): string | nullisHeaderLinkedToPrevious(variant?: SectionHeaderFooterVariant): booleanisFooterLinkedToPrevious(variant?: SectionHeaderFooterVariant): booleansetHeaderLinkedToPrevious(linked: boolean, variant?: SectionHeaderFooterVariant): booleansetFooterLinkedToPrevious(linked: boolean, variant?: SectionHeaderFooterVariant): booleansetHeaderFooterOptions(options: IHeaderFooterProps): booleanremove(): boolean
TypeScript
const document = univerAPI.getActiveDocument()const chapter = document?.findParagraphByText('Chapter 2')if (document?.isTraditional() && chapter) {  document.insertSectionBreak(chapter.getInfo().startOffset, {    nextSectionType: univerAPI.Enum.SectionType.NEXT_PAGE,  })}

APIs

Document Access

createDocument

Creates a document and returns its facade wrapper.

Signature

TypeScript
createDocument(data: Partial<IDocumentData>): FDocument

Parameters

  • data Partial<IDocumentData> — Initial document data. Pass {} to create an empty document.

Returns

  • FDocument — The created document facade wrapper.
Source: @univerjs/docs

getActiveDocument

Signature

TypeScript
getActiveDocument(): FDocument | null

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()
Source: @univerjs/docs

getDocument

Signature

TypeScript
getDocument(id: string): FDocument | null

Examples

TypeScript
const fDocument = univerAPI.getDocument('document-01')
Source: @univerjs/docs

Document Data

getDocumentDataModel

Signature

TypeScript
getDocumentDataModel(segmentId?: string): DocumentDataModel

segmentId defaults to the main body. Pass a header/footer segment id to access that segment's model.

Source: @univerjs/docs

getBody

Signature

TypeScript
getBody(segmentId?: string): IDocumentBody

segmentId defaults to the main body. Pass a header/footer segment id to access that segment's body.

Source: @univerjs/docs

save

Signature

TypeScript
save(): IDocumentData

Saves the current document, including content and resources, as IDocumentData.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const snapshot = fDocument?.save()
Source: @univerjs/docs

Identity & Lifecycle

id

Signature

TypeScript
id: string
Source: @univerjs/docs

dispose

Signature

TypeScript
dispose(): void
Source: @univerjs/docs

getId

Signature

TypeScript
getId(): string
Source: @univerjs/docs

getName

Signature

TypeScript
getName(): string
Source: @univerjs/docs

setName

TypeScript
setName(name: string): this
Source: @univerjs/docs

isModern

Signature

TypeScript
isModern(): boolean

Returns true when the document snapshot uses DocumentFlavor.MODERN.

Source: @univerjs/docs

Editing

undo

Signature

TypeScript
undo(): boolean
Source: @univerjs/docs

redo

Signature

TypeScript
redo(): boolean
Source: @univerjs/docs

insertText

Signature

TypeScript
insertText(index: number, text: string, segmentId?: string): boolean

Inserts plain text at a zero-based body offset. segmentId defaults to the main body.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()fDocument?.insertText(0, 'Hello Univer')
Source: @univerjs/docs

deleteRange

Signature

TypeScript
deleteRange(range: IFDocumentTextRange): boolean

Deletes text from the main body or from the specified header/footer segment.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()fDocument?.deleteRange({ startOffset: 0, endOffset: 5 })
Source: @univerjs/docs

ensurePageHeader

Signature

TypeScript
ensurePageHeader(pageIndex?: number): string

Ensures the page header segment exists and returns its segment id. pageIndex defaults to 0.

Source: @univerjs/docs

ensurePageFooter

Signature

TypeScript
ensurePageFooter(pageIndex?: number): string

Ensures the page footer segment exists and returns its segment id. pageIndex defaults to 0.

Source: @univerjs/docs

Paragraphs

getParagraphs

Signature

TypeScript
getParagraphs(segmentId?: string): FDocumentParagraph[]
Source: @univerjs/docs

getParagraph

Signature

TypeScript
getParagraph(paragraphId: string, segmentId?: string): FDocumentParagraph | null
Source: @univerjs/docs

findParagraphByText

Signature

TypeScript
findParagraphByText(text: string, segmentId?: string): FDocumentParagraph | null
Source: @univerjs/docs

findParagraphs

Signature

TypeScript
findParagraphs(query: string | IFDocumentParagraphQuery): FDocumentParagraph[]

query can be a text string or an object containing text, paragraphId, and segmentId.

Source: @univerjs/docs

insertParagraph

Signature

TypeScript
insertParagraph(index: number, text?: string, segmentId?: string): FDocumentParagraph

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument?.insertParagraph(0, 'Document title')paragraph?.appendText(' suffix')
Source: @univerjs/docs

appendParagraph

Signature

TypeScript
appendParagraph(text?: string, segmentId?: string): FDocumentParagraph
Source: @univerjs/docs

Paragraph Wrapper

getSegmentId

Signature

TypeScript
getSegmentId(): string
Source: @univerjs/docs

getInfo

Signature

TypeScript
getInfo(): IFDocumentParagraphInfo
Source: @univerjs/docs

getRange

Signature

TypeScript
getRange(): IFDocumentTextRange
Source: @univerjs/docs

getText

Signature

TypeScript
getText(): string
Source: @univerjs/docs

setText

Signature

TypeScript
setText(text: string): boolean
Source: @univerjs/docs

appendText

Signature

TypeScript
appendText(text: string): boolean

Appends plain text before this paragraph's trailing paragraph break.

Source: @univerjs/docs

setStyle

Signature

TypeScript
setStyle(style: IParagraphStyle): boolean
Source: @univerjs/docs

isListItem

Signature

TypeScript
isListItem(): boolean
Source: @univerjs/docs

isTask

Signature

TypeScript
isTask(): boolean
Source: @univerjs/docs

setTaskChecked

Signature

TypeScript
setTaskChecked(checked: boolean): boolean

Returns false if the paragraph is not a task/checklist item.

Source: @univerjs/docs

remove

Signature

TypeScript
remove(): boolean
Source: @univerjs/docs

Document Images

Plugin mode requires import '@univerjs/docs-drawing/facade'.

insertImage

Signature

TypeScript
insertImage(options: IFDocumentInsertImageOptions): Promise<FDocumentImage | null>

source and imageSourceType are required. Size, rotation, position, wrapping style, and insertion range are optional.

TypeScript
const document = univerAPI.getActiveDocument()const image = await document?.insertImage({  source: 'https://example.com/image.png',  imageSourceType: univerAPI.Enum.ImageSourceType.URL,  width: 320,  wrappingStyle: univerAPI.Enum.DocsImageWrappingStyle.INLINE,})image?.setRotate(15)
Source: @univerjs/docs-drawing

getImage

Signature

TypeScript
getImage(imageId: string): FDocumentImage | null
Source: @univerjs/docs-drawing

getImages

Signature

TypeScript
getImages(): FDocumentImage[]
Source: @univerjs/docs-drawing

UI

setSelection

Signature

TypeScript
setSelection(startOffset: number, endOffset: number): void

Sets the rendered selection to a text range. This method is added by @univerjs/docs-ui/facade.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()fDocument?.setSelection(10, 20)
Source: @univerjs/docs-ui
Packages@univerjs-pro/docs-table, @univerjs-pro/docs-list, @univerjs-pro/docs-callout, @univerjs-pro/docs-code, @univerjs-pro/docs-column, @univerjs-pro/docs-formula, @univerjs-pro/docs-latex, @univerjs-pro/docs-quote

Facade APIs added to FDocument by Web SDK packages for Univer Docs.

Import the corresponding package facade, such as @univerjs-pro/docs-table/facade, before using that package's APIs in plugin mode.

Rich content overview

Tables

ClassMethods
FDocumentgetTables, getTable, getTableAt, getTableAtSelection, findTableByText, findTables, insertTable, insertTableFromData
FDocumentTablegetId, getSegmentId, getInfo, describe, getRowCount, getColumnCount, getCell, getCellText, getMetadata, getSource, getRange, getTableRange, getCellRange, getCellContentRange, getCellInsertOffset, getRowRange, getRowsRange, getColumnRange, getColumnsRange, selectTable, selectRow, selectRows, selectColumn, selectColumns, selectCell, selectRange, insertRowBefore, insertRowAfter, insertRowsBefore, insertRowsAfter, appendRow, insertColumnBefore, insertColumnAfter, insertColumnsBefore, insertColumnsAfter, appendColumn, deleteRow, deleteRows, deleteColumn, deleteColumns, deleteTable, moveTableBy, moveTableToOffset, moveRow, moveRows, moveColumn, moveColumns, mergeCells, unmergeCells, setCellText, setCellBackground, setBorder, setTableBackground, setTableBorder, setTableStyle, setRowHeight, setColumnWidth, distributeRows, distributeColumns, getHeaderRowCount, setHeaderRowCount, pinHeaderRows, hasTitleRow, insertTitleRow, setColumnType, sortByColumn
FDocumentTableCellgetTable, getRowIndex, getColumnIndex, getText, getContentRange, getInsertOffset, setText, setBackgroundColor, setBorder, mergeTo, unmerge

Lists

ClassMethods
FDocumentgetLists, getList, getListItems, getListItem, getListItemAt, findListItemByText, findListItems, describeListItems, insertList
FDocumentListgetId, getSegmentId, getItems, describe, hasOrderedItems, hasUnorderedItems, isMixed, setGlyphType, setGlyphSymbol, setPrefixSuffix, setStartNumber, promote, demote
FDocumentListItemgetParagraphStartIndex, getSegmentId, describe, getText, isOrdered, isUnordered, select, setGlyphType, setGlyphSymbol, setPrefixSuffix, setStartNumber, continueNumbering, promote, demote

Blocks And Inline Elements

PackageFDocument methodsElement methods
@univerjs-pro/docs-calloutgetCallouts, getCallout, getCalloutAt, findCalloutByText, findCallouts, insertCalloutgetId, getRange, getText, getConfig, getStyle, describe, updateConfig, setBackgroundColor, setBorder, setTextColor, resetTextColor, setIcon, setIconVisible, unwrap, remove
@univerjs-pro/docs-codegetCodes, getCode, getCodeAt, findCodeByText, findCodes, insertCodegetId, getRange, getText, describe, getConfig, updateConfig, unwrap, remove
@univerjs-pro/docs-columngetColumnGroups, getColumnGroup, getColumnGroupAt, findColumnGroupByText, findColumnGroups, insertColumnGroupFDocumentColumnGroup: getId, getConfig, getRange, getColumnCount, getColumns, getColumn, getWidthRatios, describe, setWidthRatios, addColumn, deleteColumn, remove; FDocumentColumn: getId, getColumnGroupId, getIndex, getRange, getContentRange, getInsertOffset, getText
@univerjs-pro/docs-formulagetFormulas, getFormula, getFormulaAt, saveFormulaDisplayTextSnapshot, insertFormulaFDocumentFormula: getId, getRange, getFormula, getConfig, getResult, describe, update, setNumberFormat, remove, replaceWithText, convertToText; FDocumentParagraph: insertFormula, appendFormula; FDocumentTextRange: replaceWithFormula
@univerjs-pro/docs-latexgetLatexFormulas, getLatexFormula, getLatexFormulaAt, findLatexFormulaByText, findLatexFormulas, insertLatexFormulaFDocumentLatex: getId, getRange, getLatex, getConfig, describe, update; FDocumentParagraph: appendLatex, prependLatex; FDocumentTextRange: replaceWithLatex, insertLatexBefore, insertLatexAfter
@univerjs-pro/docs-quotegetQuotes, getQuote, getQuoteAt, findQuoteByText, findQuotes, insertQuotegetId, getRange, getText, getStyle, describe, setStyle, setLineColor, setTextColor, unwrap, remove

Rich content signatures

Table Entry Points

TypeScript
getTables(segmentId?: string): FDocumentTable[]getTable(tableId: string, segmentId?: string): FDocumentTable | nullgetTableAt(index: number, segmentId?: string): FDocumentTable | nullgetTableAtSelection(): FDocumentTable | nullfindTableByText(text: string, segmentId?: string): FDocumentTable | nullfindTables(query: string | IDocsTableFindQuery, segmentId?: string): FDocumentTable[]insertTable(rows: number, columns: number, options?: IDocsTableInsertOptions): FDocumentTable | nullinsertTableFromData(data: string[][], options?: IDocsTableInsertOptions): FDocumentTable | null

List Entry Points

TypeScript
getLists(segmentId?: string): FDocumentList[]getList(listId: string, segmentId?: string): FDocumentList | nullgetListItems(segmentId?: string): FDocumentListItem[]getListItem(paragraphStartIndex: number, segmentId?: string): FDocumentListItem | nullgetListItemAt(offset: number, segmentId?: string): FDocumentListItem | nullfindListItemByText(text: string, segmentId?: string): FDocumentListItem | nullfindListItems(query: string | IDocsListFindQuery, segmentId?: string): FDocumentListItem[]describeListItems(segmentId?: string): IDocsListItemInfo[]insertList(paragraphOrOptions?: FDocumentParagraph | IDocsListInsertFacadeOptions, options?: IDocsListInsertParagraphFacadeOptions): FDocumentList | null

Table Wrapper APIs

TypeScript
// FDocumentTablegetId(): stringgetSegmentId(): stringgetInfo(): IDocsTableInfodescribe(): IDocsTableDescriptiongetRowCount(): numbergetColumnCount(): numbergetCell(row: number, column: number): FDocumentTableCell | nullgetCellText(row: number, column: number): stringgetMetadata(): IDocsTableMetadata | undefinedgetSource(): ITable | undefinedgetRange(): IDocsTableOffsetRange | nullgetTableRange(): IDocsTableCellRangegetCellRange(row: number, column: number): IDocsTableCellRangegetCellContentRange(row: number, column: number): IDocsTableCellContentRange | nullgetCellInsertOffset(row: number, column: number): number | nullgetRowRange(row: number): IDocsTableCellRangegetRowsRange(startRow: number, count?: number): IDocsTableCellRangegetColumnRange(column: number): IDocsTableCellRangegetColumnsRange(startColumn: number, count?: number): IDocsTableCellRangeselectTable(): booleanselectRow(row: number): booleanselectRows(startRow: number, count?: number): booleanselectColumn(column: number): booleanselectColumns(startColumn: number, count?: number): booleanselectCell(row: number, column: number): booleanselectRange(range: IDocsTableCellRange, kind: Exclude<DocsTableSelectionKind, DocsTableSelectionKind.None | DocsTableSelectionKind.Text>): booleaninsertRowBefore(row: number): booleaninsertRowAfter(row: number): booleaninsertRowsBefore(row: number, count: number): booleaninsertRowsAfter(row: number, count: number): booleanappendRow(): booleaninsertColumnBefore(column: number): booleaninsertColumnAfter(column: number): booleaninsertColumnsBefore(column: number, count: number): booleaninsertColumnsAfter(column: number, count: number): booleanappendColumn(): booleandeleteRow(row: number): booleandeleteRows(startRow: number, count?: number): booleandeleteColumn(column: number): booleandeleteColumns(startColumn: number, count?: number): booleandeleteTable(): booleanmoveTableBy(deltaX: number, deltaY: number): booleanmoveTableToOffset(offset: number): booleanmoveRow(row: number, targetRow: number, position: DocsTableRowInsertPosition): booleanmoveRows(startRow: number, count: number, targetRow: number, position: DocsTableRowInsertPosition): booleanmoveColumn(column: number, targetColumn: number, position: DocsTableColumnInsertPosition): booleanmoveColumns(startColumn: number, count: number, targetColumn: number, position: DocsTableColumnInsertPosition): booleanmergeCells(range: IDocsTableCellRange): booleanunmergeCells(range: IDocsTableCellRange): booleansetCellText(row: number, column: number, text: string): booleansetCellBackground(range: IDocsTableCellRange, color: string): booleansetBorder(range: IDocsTableCellRange, options: IDocsTableBorderOptions): booleansetTableBackground(color: string): booleansetTableBorder(border: IDocsTableBorderOptions): booleansetTableStyle(style: IDocsTableStyle): booleansetRowHeight(row: number, height: number): booleansetColumnWidth(column: number, width: number): booleandistributeRows(startRow?: number, count?: number): booleandistributeColumns(startColumn?: number, count?: number): booleangetHeaderRowCount(): numbersetHeaderRowCount(count: number): booleanpinHeaderRows(count: number): booleanhasTitleRow(): booleaninsertTitleRow(): booleansetColumnType(column: number, config: IDocsTableColumnTypeConfig): booleansortByColumn(column: number, direction: DocsTableSortDirection): boolean// FDocumentTableCellgetTable(): FDocumentTablegetRowIndex(): numbergetColumnIndex(): numbergetText(): stringgetContentRange(): IDocsTableCellContentRange | nullgetInsertOffset(): number | nullsetText(text: string): booleansetBackgroundColor(color: string): booleansetBorder(border: IDocsTableBorderOptions): booleanmergeTo(rowSpan: number, columnSpan: number): booleanunmerge(): boolean

List Wrapper APIs

TypeScript
// FDocumentListgetId(): stringgetSegmentId(): stringgetItems(): FDocumentListItem[]describe(): IDocsListInfohasOrderedItems(): booleanhasUnorderedItems(): booleanisMixed(): booleansetGlyphType(glyphType: ListGlyphType): booleansetGlyphSymbol(symbol: string): booleansetPrefixSuffix(prefix: string, suffix: string): booleansetStartNumber(startNumber: number): booleanpromote(): booleandemote(): boolean// FDocumentListItemgetParagraphStartIndex(): numbergetSegmentId(): stringdescribe(): IDocsListItemInfo | nullgetText(): stringisOrdered(): booleanisUnordered(): booleanselect(mode?: DocsListSelectionMode): booleansetGlyphType(glyphType: ListGlyphType, options?: IDocsListOperationOptions): booleansetGlyphSymbol(symbol: string, options?: IDocsListOperationOptions): booleansetPrefixSuffix(prefix: string, suffix: string, options?: IDocsListOperationOptions): booleansetStartNumber(startNumber: number, options?: IDocsListStartNumberOptions): booleancontinueNumbering(): booleanpromote(options?: IDocsListOperationOptions): booleandemote(options?: IDocsListOperationOptions): boolean

Block Entry Points

TypeScript
insertCallout(paragraphOrOptions?: FDocumentParagraph | IDocsCalloutInsertFacadeOptions, options?: IDocsCalloutInsertParagraphFacadeOptions): FDocumentCallout | nullinsertCode(paragraphOrOptions?: FDocumentParagraph | IDocsCodeInsertFacadeOptions, options?: IDocsCodeInsertParagraphFacadeOptions): FDocumentCode | nullinsertColumnGroup(columnCount: number, options?: IDocsColumnInsertFacadeOptions): FDocumentColumnGroup | nullinsertLatexFormula(options: IDocsLatexInsertFacadeOptions): FDocumentLatex | nullinsertQuote(paragraphOrOptions?: FDocumentParagraph | IDocsQuoteInsertFacadeOptions, options?: IDocsQuoteInsertParagraphFacadeOptions): FDocumentQuote | null

Callout and quote styles

TypeScript
// FDocumentCalloutgetStyle(): IDocsCalloutStylesetBackgroundColor(backgroundColor: string): booleansetBorder(border: Partial<IDocsCalloutBorderStyle>): booleansetTextColor(value: string): booleanresetTextColor(): booleansetIcon(icon: string): booleansetIconVisible(showIcon: boolean): boolean// FDocumentQuotegetStyle(): IDocsQuoteStylesetStyle(style: Partial<IDocsQuoteStyle>): booleansetLineColor(lineColor: string): booleansetTextColor(textColor: string): boolean
TypeScript
const callout = fDocument?.findCalloutByText('Important')callout?.setBackgroundColor('#FFF4E5')callout?.setBorder({ color: '#E6A23C', width: 2 })callout?.setTextColor('#5C3B00')const quote = fDocument?.findQuoteByText('Decision')quote?.setStyle({ lineColor: '#5B5FC7', textColor: '#242424' })

LaTeX can also be inserted from stable paragraph and text-range handles:

TypeScript
// FDocumentParagraphappendLatex(latex: string, options?: IDocsLatexCreateFacadeOptions): FDocumentLatex | nullprependLatex(latex: string, options?: IDocsLatexCreateFacadeOptions): FDocumentLatex | null// FDocumentTextRangereplaceWithLatex(latex: string, options?: IDocsLatexCreateFacadeOptions): FDocumentLatex | nullinsertLatexBefore(latex: string, options?: IDocsLatexCreateFacadeOptions): FDocumentLatex | nullinsertLatexAfter(latex: string, options?: IDocsLatexCreateFacadeOptions): FDocumentLatex | null

Inline Data Formulas

Import @univerjs-pro/docs-formula/facade to add formula methods to documents, paragraphs, and text ranges.

TypeScript
// FDocumentgetFormulas(): FDocumentFormula[]getFormula(rangeId: string): FDocumentFormula | nullgetFormulaAt(offset: number): FDocumentFormula | nullsaveFormulaDisplayTextSnapshot(): IDocumentDatainsertFormula(options: IDocFormulaInsertFacadeOptions): FDocumentFormula | null// FDocumentParagraphinsertFormula(offset: number, formula: string, options?: IDocFormulaCreateFacadeOptions): FDocumentFormula | nullappendFormula(formula: string, options?: IDocFormulaCreateFacadeOptions): FDocumentFormula | null// FDocumentTextRangereplaceWithFormula(formula: string, options?: IDocFormulaCreateFacadeOptions): FDocumentFormula | null// FDocumentFormulagetId(): stringgetRange(): IDocFormulaRange | nullgetFormula(): stringgetConfig(): IDocFormulaConfig | nullgetResult(): IDocFormulaResult | nulldescribe(): IDocFormulaInfo | nullupdate(options: IDocFormulaUpdateFacadeOptions): booleansetNumberFormat(numberFormat?: { pattern: string }): booleanremove(): booleanreplaceWithText(text: string): booleanconvertToText(): boolean
TypeScript
const document = univerAPI.getActiveDocument()const paragraph = document?.appendParagraph('Revenue: ')const formula = paragraph?.appendFormula('=1000/4', {  numberFormat: { pattern: '$#,##0.00' },})console.log(formula?.getResult()?.text)

Enums

TypeScript
// univerAPI.Enum from @univerjs-pro/docs-table/facadeDocsTableInsertTablePosition: typeof DocsTableInsertTablePositionDocsTableColumnType: typeof DocsTableColumnTypeDocsTableSelectionKind: typeof DocsTableSelectionKindDocsTableRowInsertPosition: typeof DocsTableRowInsertPositionDocsTableColumnInsertPosition: typeof DocsTableColumnInsertPositionDocsTableBorderPreset: typeof DocsTableBorderPresetDocsTableSortDirection: typeof DocsTableSortDirectionDashStyleType: typeof DashStyleType// univerAPI.Enum from @univerjs-pro/docs-list/facadePresetListType: typeof PresetListTypeDocsListSelectionMode: typeof DocsListSelectionModeListGlyphType: typeof ListGlyphType// univerAPI.Enum from @univerjs-pro/docs-column/facadeDocsColumnPositionEnum: typeof DocsColumnPositionEnum

Rich content examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const table = fDocument?.insertTableFromData([  ['Name', 'Score'],  ['Ada', '100'],])table?.setCellText(1, 1, '98')

Source: @univerjs-pro/docs-table, @univerjs-pro/docs-list, @univerjs-pro/docs-callout, @univerjs-pro/docs-code, @univerjs-pro/docs-column, @univerjs-pro/docs-formula, @univerjs-pro/docs-latex, @univerjs-pro/docs-quote

Footnotes and endnotes

Import @univerjs-pro/docs-reference/facade and register UniverDocsReferencePlugin to use these methods on a traditional paginated document. Insertion returns a stable note ID, or null when the position, content, document mode, or permission does not allow the operation.

MethodsPurpose
insertFootnote(offset, content?), insertEndnote(offset, content?)Insert a reference at a UTF-16 main-body offset and create note content
getFootnotes(), getEndnotes()Read detached note data in reference order
deleteFootnote(noteId), deleteEndnote(noteId)Delete a note and its reference
getFootnoteSettings(sectionId?), getEndnoteSettings(sectionId?)Read explicit numbering and placement settings
setFootnoteSettings(settings, sectionId?), setEndnoteSettings(settings, sectionId?)Replace settings, or reset them with null

See Footnotes and endnotes for setup and examples. Displayed numbering may change after layout; use the stable note ID with getParagraphs(noteId) or getTextRange() when addressing note content.

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.