Document Pro
| 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 Univer SDK Pro 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.
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 |
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 | nullList 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 | nullTable 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(): booleanList 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): booleanBlock 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 | nullCallout 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): booleanTypeScript
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 | nullInline 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(): booleanTypeScript
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 DocsColumnPositionEnumExamples
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
How is this guide?