Document
| 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 underlyinguniverinstance directly, useuniver.createUnit(UniverInstanceType.UNIVER_DOC, data).
Overview
@univerjs/docs
| Class | Method | Description |
|---|---|---|
univerAPI | createDocument | Create a document and return its facade wrapper. |
univerAPI | getActiveDocument | Get the currently focused document. |
univerAPI | getDocument | Get a document facade wrapper by document id. |
FDocument | getDocumentDataModel | Get the document data model. |
FDocument | getBody | Get the main body or a header/footer body by segment id. |
FDocument | dispose | Dispose the facade wrapper. |
FDocument | getId | Get the document id. |
FDocument | getPermission, getEntityPermission | Access command-backed unit and object permissions. |
FDocument | getName | Get the document name. |
FDocument | setName | Update the document name. |
FDocument | getDocumentFlavor | Get the document flavor. |
FDocument | isTraditional | Check whether the document uses traditional pagination. |
FDocument | isModern | Check whether the document uses the modern document flavor. |
FDocument | save | Save and return the document snapshot data. |
FDocument | undo | Undo the last operation in the focused document. |
FDocument | redo | Redo the last undone operation in the focused document. |
FDocument | ensurePageHeader | Ensure that a page header segment exists. |
FDocument | ensurePageFooter | Ensure that a page footer segment exists. |
FDocument | getHeaderFooterOptions, setHeaderFooterOptions | Read or update document-level header and footer settings. |
FDocument | insertText | Insert plain text at a body offset. |
FDocument | getTextRange | Create a fixed text-range facade. |
FDocument | getSections, getSection, getSectionAt | Resolve traditional document sections. |
FDocument | insertSectionBreak, insertColumnBreak, insertHorizontalRule | Insert structural document elements. |
FDocument | getParagraphs | Get all paragraph wrappers for a body segment. |
FDocument | getParagraph | Get a paragraph wrapper by paragraph id. |
FDocument | findParagraphByText | Find the first paragraph containing text. |
FDocument | findParagraphs | Find paragraphs by text, paragraph id, or segment id. |
FDocument | insertParagraph | Insert a plain-text paragraph at an index. |
FDocument | appendParagraph | Append a plain-text paragraph to the body. |
FDocument | deleteRange | Delete a text range from the body. |
FDocumentParagraph | getSegmentId | Get the paragraph segment id. |
FDocumentParagraph | getId | Get the stable paragraph id. |
FDocumentParagraph | getPermission | Access the paragraph's effective edit permission. |
FDocumentParagraph | getInfo | Get resolved paragraph metadata. |
FDocumentParagraph | getRange | Get the paragraph text range. |
FDocumentParagraph | getTextRange, findText, findAllText | Create or find fixed text ranges in the paragraph. |
FDocumentParagraph | getText | Get the paragraph plain text. |
FDocumentParagraph | setText | Replace the paragraph plain text. |
FDocumentParagraph | appendText | Append plain text before the paragraph break. |
FDocumentParagraph | setStyle | Apply paragraph or text style. |
FDocumentParagraph | isListItem | Check whether the paragraph has list metadata. |
FDocumentParagraph | isTask | Check whether the paragraph is a checklist item. |
FDocumentParagraph | setTaskChecked | Set checklist state for a task paragraph. |
FDocumentParagraph | remove | Remove the paragraph. |
@univerjs/docs-thread-comment
| Class | Methods | Description |
|---|---|---|
FDocumentTextRange | createCommentAsync, getComments, listCommentsAsync | Create and query comments anchored to a fixed text range. |
@univerjs/docs-ui
| Class | Method | Description |
|---|---|---|
FDocument | setSelection | Set the rendered selection range in a document. |
@univerjs/docs-drawing
| Class | Method | Description |
|---|---|---|
FDocument | insertImage | Insert an image into the document. |
FDocument | getImage | Get an image by drawing id. |
FDocument | getImages | Get all document images in drawing order. |
FDocumentImage | getId, getSource, getSize, getAngle | Read image identity, source, and transform. |
FDocumentImage | setSize, setRotate, setPositionH, setPositionV | Update image geometry. |
FDocumentImage | setWrappingStyle, setForward, setBackward, setFront, setBack, remove | Update 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.
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
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.
// 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): booleanFDocumentSection supports column layout, section types, page setup, section-specific headers and footers, and removal:
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(): booleanconst 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
createDocument(data: Partial<IDocumentData>): FDocumentParameters
dataPartial<IDocumentData>— Initial document data. Pass{}to create an empty document.
Returns
FDocument— The created document facade wrapper.
@univerjs/docs
getActiveDocument
Signature
getActiveDocument(): FDocument | nullExamples
const fDocument = univerAPI.getActiveDocument()@univerjs/docs
getDocument
Signature
getDocument(id: string): FDocument | nullExamples
const fDocument = univerAPI.getDocument('document-01')@univerjs/docs
Document Data
getDocumentDataModel
Signature
getDocumentDataModel(segmentId?: string): DocumentDataModelsegmentId defaults to the main body. Pass a header/footer segment id to access that segment's model.
@univerjs/docs
getBody
Signature
getBody(segmentId?: string): IDocumentBodysegmentId defaults to the main body. Pass a header/footer segment id to access that segment's body.
@univerjs/docs
save
Signature
save(): IDocumentDataSaves the current document, including content and resources, as IDocumentData.
Examples
const fDocument = univerAPI.getActiveDocument()const snapshot = fDocument?.save()@univerjs/docs
Identity & Lifecycle
id
Signature
id: string@univerjs/docs
dispose
Signature
dispose(): void@univerjs/docs
getId
Signature
getId(): string@univerjs/docs
getName
Signature
getName(): string@univerjs/docs
setName
setName(name: string): this@univerjs/docs
isModern
Signature
isModern(): booleanReturns true when the document snapshot uses DocumentFlavor.MODERN.
@univerjs/docs
Editing
undo
Signature
undo(): boolean@univerjs/docs
redo
Signature
redo(): boolean@univerjs/docs
insertText
Signature
insertText(index: number, text: string, segmentId?: string): booleanInserts plain text at a zero-based body offset. segmentId defaults to the main body.
Examples
const fDocument = univerAPI.getActiveDocument()fDocument?.insertText(0, 'Hello Univer')@univerjs/docs
deleteRange
Signature
deleteRange(range: IFDocumentTextRange): booleanDeletes text from the main body or from the specified header/footer segment.
Examples
const fDocument = univerAPI.getActiveDocument()fDocument?.deleteRange({ startOffset: 0, endOffset: 5 })@univerjs/docs
Header & Footer
ensurePageHeader
Signature
ensurePageHeader(pageIndex?: number): stringEnsures the page header segment exists and returns its segment id. pageIndex defaults to 0.
@univerjs/docs
ensurePageFooter
Signature
ensurePageFooter(pageIndex?: number): stringEnsures the page footer segment exists and returns its segment id. pageIndex defaults to 0.
@univerjs/docs
Paragraphs
getParagraphs
Signature
getParagraphs(segmentId?: string): FDocumentParagraph[]@univerjs/docs
getParagraph
Signature
getParagraph(paragraphId: string, segmentId?: string): FDocumentParagraph | null@univerjs/docs
findParagraphByText
Signature
findParagraphByText(text: string, segmentId?: string): FDocumentParagraph | null@univerjs/docs
findParagraphs
Signature
findParagraphs(query: string | IFDocumentParagraphQuery): FDocumentParagraph[]query can be a text string or an object containing text, paragraphId, and segmentId.
@univerjs/docs
insertParagraph
Signature
insertParagraph(index: number, text?: string, segmentId?: string): FDocumentParagraphExamples
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument?.insertParagraph(0, 'Document title')paragraph?.appendText(' suffix')@univerjs/docs
appendParagraph
Signature
appendParagraph(text?: string, segmentId?: string): FDocumentParagraph@univerjs/docs
Paragraph Wrapper
getSegmentId
Signature
getSegmentId(): string@univerjs/docs
getInfo
Signature
getInfo(): IFDocumentParagraphInfo@univerjs/docs
getRange
Signature
getRange(): IFDocumentTextRange@univerjs/docs
getText
Signature
getText(): string@univerjs/docs
setText
Signature
setText(text: string): boolean@univerjs/docs
appendText
Signature
appendText(text: string): booleanAppends plain text before this paragraph's trailing paragraph break.
Source:@univerjs/docs
setStyle
Signature
setStyle(style: IParagraphStyle): boolean@univerjs/docs
isListItem
Signature
isListItem(): boolean@univerjs/docs
isTask
Signature
isTask(): boolean@univerjs/docs
setTaskChecked
Signature
setTaskChecked(checked: boolean): booleanReturns false if the paragraph is not a task/checklist item.
@univerjs/docs
remove
Signature
remove(): boolean@univerjs/docs
Document Images
Plugin mode requires import '@univerjs/docs-drawing/facade'.
insertImage
Signature
insertImage(options: IFDocumentInsertImageOptions): Promise<FDocumentImage | null>source and imageSourceType are required. Size, rotation, position, wrapping style, and insertion range are optional.
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)@univerjs/docs-drawing
getImage
Signature
getImage(imageId: string): FDocumentImage | null@univerjs/docs-drawing
getImages
Signature
getImages(): FDocumentImage[]@univerjs/docs-drawing
UI
setSelection
Signature
setSelection(startOffset: number, endOffset: number): voidSets the rendered selection to a text range. This method is added by @univerjs/docs-ui/facade.
Examples
const fDocument = univerAPI.getActiveDocument()fDocument?.setSelection(10, 20)@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
| Class | Methods |
|---|---|
FDocument | getTables, getTable, getTableAt, getTableAtSelection, findTableByText, findTables, insertTable, insertTableFromData |
FDocumentTable | getId, 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 |
FDocumentTableCell | getTable, getRowIndex, getColumnIndex, getText, getContentRange, getInsertOffset, setText, setBackgroundColor, setBorder, mergeTo, unmerge |
Lists
| Class | Methods |
|---|---|
FDocument | getLists, getList, getListItems, getListItem, getListItemAt, findListItemByText, findListItems, describeListItems, insertList |
FDocumentList | getId, getSegmentId, getItems, describe, hasOrderedItems, hasUnorderedItems, isMixed, setGlyphType, setGlyphSymbol, setPrefixSuffix, setStartNumber, promote, demote |
FDocumentListItem | getParagraphStartIndex, getSegmentId, describe, getText, isOrdered, isUnordered, select, setGlyphType, setGlyphSymbol, setPrefixSuffix, setStartNumber, continueNumbering, promote, demote |
Blocks And Inline Elements
| Package | FDocument methods | Element methods |
|---|---|---|
@univerjs-pro/docs-callout | getCallouts, getCallout, getCalloutAt, findCalloutByText, findCallouts, insertCallout | getId, getRange, getText, getConfig, getStyle, describe, updateConfig, setBackgroundColor, setBorder, setTextColor, resetTextColor, setIcon, setIconVisible, unwrap, remove |
@univerjs-pro/docs-code | getCodes, getCode, getCodeAt, findCodeByText, findCodes, insertCode | getId, getRange, getText, describe, getConfig, updateConfig, unwrap, remove |
@univerjs-pro/docs-column | getColumnGroups, getColumnGroup, getColumnGroupAt, findColumnGroupByText, findColumnGroups, insertColumnGroup | FDocumentColumnGroup: getId, getConfig, getRange, getColumnCount, getColumns, getColumn, getWidthRatios, describe, setWidthRatios, addColumn, deleteColumn, remove; FDocumentColumn: getId, getColumnGroupId, getIndex, getRange, getContentRange, getInsertOffset, getText |
@univerjs-pro/docs-formula | getFormulas, getFormula, getFormulaAt, saveFormulaDisplayTextSnapshot, insertFormula | FDocumentFormula: getId, getRange, getFormula, getConfig, getResult, describe, update, setNumberFormat, remove, replaceWithText, convertToText; FDocumentParagraph: insertFormula, appendFormula; FDocumentTextRange: replaceWithFormula |
@univerjs-pro/docs-latex | getLatexFormulas, getLatexFormula, getLatexFormulaAt, findLatexFormulaByText, findLatexFormulas, insertLatexFormula | FDocumentLatex: getId, getRange, getLatex, getConfig, describe, update; FDocumentParagraph: appendLatex, prependLatex; FDocumentTextRange: replaceWithLatex, insertLatexBefore, insertLatexAfter |
@univerjs-pro/docs-quote | getQuotes, getQuote, getQuoteAt, findQuoteByText, findQuotes, insertQuote | getId, getRange, getText, getStyle, describe, setStyle, setLineColor, setTextColor, unwrap, remove |
Rich content signatures
Table Entry Points
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 | nullList Entry Points
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 | nullTable Wrapper APIs
// 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(): booleanList Wrapper APIs
// 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): booleanBlock Entry Points
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 | nullCallout and quote styles
// 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): booleanconst 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:
// 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 | nullInline Data Formulas
Import @univerjs-pro/docs-formula/facade to add formula methods to documents, paragraphs, and text ranges.
// 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(): booleanconst document = univerAPI.getActiveDocument()const paragraph = document?.appendParagraph('Revenue: ')const formula = paragraph?.appendFormula('=1000/4', { numberFormat: { pattern: '$#,##0.00' },})console.log(formula?.getResult()?.text)Enums
// 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 DocsColumnPositionEnumRich content examples
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.
| Methods | Purpose |
|---|---|
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.
你觉得这篇文档如何?