FDocument
Facade API object bounded to a document. It provides a set of methods to interact with the document.
Access
Access through:
FUniver.createDocument()FUniver.getActiveDocument()FUniver.getDocument()FCollaboration.loadDocAsync()
Setup
Register @univerjs/docs or a preset that includes it. In plugin mode, import @univerjs/docs/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs/docs
FDocument.appendParagraph
Append a plain-text paragraph at the end of the body.
appendParagraph(text?: string, segmentId?: string): FDocumentParagraphParameters
text— Optional. Default:''. The paragraph text. Defaults to an empty paragraph.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The appended paragraph wrapper.
Examples
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument.appendParagraph('Summary')console.log(paragraph.getText())const footerSegmentId = fDocument.ensurePageFooter()const footerParagraph = fDocument.appendParagraph('Confidential', footerSegmentId)console.log(footerParagraph.getText())Types: FDocumentParagraph
Package: @univerjs/docs · Type definitions
FDocument.deleteRange
Delete a range from the body.
deleteRange(range: IFDocumentTextRange): booleanParameters
range— Required. The text range to delete.
Returns
true if the range was deleted.
Examples
const fDocument = univerAPI.getActiveDocument()fDocument.deleteRange({ startOffset: 0, endOffset: 5 })const headerSegmentId = fDocument.ensurePageHeader()fDocument.deleteRange({ startOffset: 0, endOffset: 5, segmentId: headerSegmentId })Types: IFDocumentTextRange
Package: @univerjs/docs · Type definitions
FDocument.dispose
Releases this facade's resources. Use univerAPI.disposeUnit() to unload the owning unit.
dispose(): voidPackage: @univerjs/docs · Type definitions
FDocument.ensurePageFooter
Ensure the page footer segment exists and return its segment id.
ensurePageFooter(pageIndex?: number): stringParameters
pageIndex— Optional. Default:0. The zero-based page index. Defaults to the first page.
Returns
The footer segment id.
Examples
const fDocument = univerAPI.getActiveDocument()const footerSegmentId = fDocument.ensurePageFooter()fDocument.insertText(0, 'Footer text', footerSegmentId)Package: @univerjs/docs · Type definitions
FDocument.ensurePageHeader
Ensure the page header segment exists and return its segment id.
ensurePageHeader(pageIndex?: number): stringParameters
pageIndex— Optional. Default:0. The zero-based page index. Defaults to the first page.
Returns
The header segment id.
Examples
const fDocument = univerAPI.getActiveDocument()const headerSegmentId = fDocument.ensurePageHeader()fDocument.insertText(0, 'Header text', headerSegmentId)Package: @univerjs/docs · Type definitions
FDocument.findParagraphByText
Find a paragraph by its text content and segment id.
findParagraphByText(text: string, segmentId?: string): FDocumentParagraph | nullParameters
text— Required. The text content to search for.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The paragraph facade instance, or null if the paragraph is not found.
Examples
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument.findParagraphByText('Hello')console.log(paragraph)const footerSegmentId = fDocument.ensurePageFooter()const footerParagraph = fDocument.findParagraphByText('Page', footerSegmentId)console.log(footerParagraph)Types: FDocumentParagraph
Package: @univerjs/docs · Type definitions
FDocument.findParagraphs
Find paragraphs by a query object, which can include text content, paragraph id, and segment id.
findParagraphs(query: string | IFDocumentParagraphQuery): FDocumentParagraph[]Parameters
query— Required. The query object or text content to search for.
Returns
An array of paragraph facade instances that match the query.
Examples
const fDocument = univerAPI.getActiveDocument()const paragraphsWithText = fDocument.findParagraphs('Hello')console.log(paragraphsWithText)const paragraphsWithId = fDocument.findParagraphs({ paragraphId: 'paragraph-01' })console.log(paragraphsWithId)const headerSegmentId = fDocument.ensurePageHeader()const paragraphsWithSegment = fDocument.findParagraphs({ segmentId: headerSegmentId })console.log(paragraphsWithSegment)Types: FDocumentParagraph · IFDocumentParagraphQuery
Package: @univerjs/docs · Type definitions
FDocument.getBody
Get the document body or header/footer body by the segment id. The main body has an empty segment id. The header and footer body have their respective segment ids.
getBody(segmentId?: string): IDocumentBodyParameters
segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The document body.
Examples
const fDocument = univerAPI.getActiveDocument()console.log(fDocument.getBody()) // Get the main bodyconst footerSegmentId = fDocument.ensurePageFooter()console.log(fDocument.getBody(footerSegmentId)) // Get the footer bodyTypes: IDocumentBody
Package: @univerjs/docs · Type definitions
FDocument.getCustomBlockLayout
Returns the document's custom blocks in stable model order.
This method is available in Node/headless environments and does not perform font measurement, line wrapping, pagination, or rendering.
getCustomBlockLayout(): IDocumentCustomBlockLayoutReturns
Custom block identifiers and model positions.
Examples
const document = univerAPI.getActiveDocument()const layout = document?.getCustomBlockLayout()console.log(layout?.blocks)Types: IDocumentCustomBlockLayout
Package: @univerjs/docs · Type definitions
FDocument.getDocumentDataModel
Get the document data model of the document.
getDocumentDataModel(segmentId?: string): DocumentDataModelParameters
segmentId— Optional. Default:''. The segment id used to get the header/footer data model. Defaults to an empty string for the document data model of the document.
Returns
The document data model.
Examples
const fDocument = univerAPI.getActiveDocument()console.log(fDocument.getDocumentDataModel())const headerSegmentId = fDocument.ensurePageHeader()console.log(fDocument.getDocumentDataModel(headerSegmentId))Types: DocumentDataModel
Package: @univerjs/docs · Type definitions
FDocument.getDocumentFlavor
Returns the document's explicit layout flavor.
Use this method when all three states matter. Do not infer a Traditional
document from !isModern(): that expression is also true for
DocumentFlavor.UNSPECIFIED.
getDocumentFlavor(): DocumentFlavorReturns
TRADITIONAL, MODERN, or UNSPECIFIED.
Examples
const document = univerAPI.getActiveDocument()if (!document) { throw new Error('No active document')}switch (document.getDocumentFlavor()) { case univerAPI.Enum.DocumentFlavor.TRADITIONAL: console.log('Word-compatible physical pagination is available') break case univerAPI.Enum.DocumentFlavor.MODERN: console.log('Use Modern Doc layout APIs such as ColumnGroup') break default: console.log('Resolve the unspecified flavor before using flavor-specific APIs')}Types: DocumentFlavor
Package: @univerjs/docs · Type definitions
FDocument.getEntityPermission
Returns the permission facade for an entity with a stable id, such as a Table, Drawing, or Custom Block.
Parent Section and Paragraph permission ceilings are resolved from the current Document model.
getEntityPermission(segmentId: string, entityType: string, entityId: string): FDocumentObjectPermissionParameters
segmentId— Required. Segment id, or an empty string for the main body.entityType— Required. Stable entity type used by the owning Doc feature.entityId— Required. Stable entity id.
Returns
Effective permission facade for the entity.
Examples
Make one drawing read-only
const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active Document.')const snapshot = document.getDocumentDataModel().getSnapshot()const drawingId = snapshot.drawingsOrder?.[0]if (!drawingId) throw new Error('Drawing not found.')await document.getEntityPermission('', 'drawing', drawingId).setReadOnly()Types: FDocumentObjectPermission
Package: @univerjs/docs · Type definitions
FDocument.getHeaderFooterOptions
Returns document-level header/footer switches and margins. Margin values use 96-DPI layout pixels.
getHeaderFooterOptions(): IHeaderFooterPropsExamples
const fDocument = univerAPI.getActiveDocument()console.log(fDocument?.getHeaderFooterOptions())Types: IHeaderFooterProps
Package: @univerjs/docs · Type definitions
FDocument.getId
Get the document id.
getId(): stringReturns
The document id.
Examples
const fDocument = univerAPI.getActiveDocument()console.log(fDocument.getId())Package: @univerjs/docs · Type definitions
FDocument.getName
Get the document name.
getName(): stringReturns
The document name.
Examples
const fDocument = univerAPI.getActiveDocument()console.log(fDocument.getName())Package: @univerjs/docs · Type definitions
FDocument.getParagraph
Get a paragraph by its paragraph id and segment id.
getParagraph(paragraphId: string, segmentId?: string): FDocumentParagraph | nullParameters
paragraphId— Required. The paragraph id.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The paragraph facade instance, or null if the paragraph is not found.
Examples
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument.getParagraph('paragraph-01')console.log(paragraph)const headerSegmentId = fDocument.ensurePageHeader()const headerParagraph = fDocument.getParagraph('header-paragraph-01', headerSegmentId)console.log(headerParagraph)Types: FDocumentParagraph
Package: @univerjs/docs · Type definitions
FDocument.getParagraphs
Get all paragraphs in the document body or header/footer body by the segment id.
getParagraphs(segmentId?: string): FDocumentParagraph[]Parameters
segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
An array of paragraph facade instances.
Examples
const fDocument = univerAPI.getActiveDocument()const paragraphs = fDocument.getParagraphs()console.log(paragraphs)const headerSegmentId = fDocument.ensurePageHeader()const headerParagraphs = fDocument.getParagraphs(headerSegmentId)console.log(headerParagraphs)Types: FDocumentParagraph
Package: @univerjs/docs · Type definitions
FDocument.getPermission
Returns the Document unit permission facade.
getPermission(): FDocumentPermissionReturns
Permission facade for Edit, Copy, Print, Export, and Comment.
Examples
const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active Document.')await document.getPermission().setReadOnly()Types: FDocumentPermission
Package: @univerjs/docs · Type definitions
FDocument.getSection
Returns a traditional section by zero-based index, or null in modern documents.
getSection(index: number): FDocumentSection | nullParameters
index— Required. Zero-based section index.
Returns
The matching section, or null if none exists or the document is not Traditional.
Examples
const fDocument = univerAPI.getActiveDocument()const firstSection = fDocument?.getSection(0)console.log(firstSection?.describe())Types: FDocumentSection
Package: @univerjs/docs · Type definitions
FDocument.getSectionAt
Returns the traditional section containing a data-stream offset, or null in modern documents.
getSectionAt(offset: number): FDocumentSection | nullParameters
offset— Required. Zero-based data-stream offset in the main document body.
Returns
The matching section, or null if none exists or the document is not Traditional.
Examples
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument?.findParagraphByText('Launch')const offset = paragraph?.getInfo().startOffsetconst section = offset == null ? null : fDocument?.getSectionAt(offset)console.log(section?.getId())Types: FDocumentSection
Package: @univerjs/docs · Type definitions
FDocument.getSections
Returns traditional document sections backed by persisted SectionBreak ids. Modern documents use ColumnGroup instead and return an empty array from this read API.
getSections(): FDocumentSection[]Examples
const fDocument = univerAPI.getActiveDocument()const sections = fDocument?.getSections() ?? []console.log(sections.map((section) => section.describe()))Types: FDocumentSection
Package: @univerjs/docs · Type definitions
FDocument.getTextRange
Creates a facade for reading and styling a document text range. The end offset is exclusive, and offsets are scoped to the selected body segment.
getTextRange(startOffset: number, endOffset: number, segmentId?: string): FDocumentTextRangeParameters
startOffset— Required. The inclusive start offset.endOffset— Required. The exclusive end offset.segmentId— Optional. Default:''. The header/footer segment id, or an empty string for the main body.
Returns
A fixed text-range facade.
Examples
const range = univerAPI.getActiveDocument()?.getTextRange(0, 5)console.log(range?.describe())range?.setTextStyle({ bl: 1 })Types: FDocumentTextRange
Package: @univerjs/docs · Type definitions
FDocument.id
The document unit id used to identify this document in commands and snapshots.
readonly id: stringPackage: @univerjs/docs · Type definitions
FDocument.insertColumnBreak
Inserts a column-break token in a traditional document.
In a single-column section, the traditional renderer advances to the next physical page.
Modern documents must use ColumnGroup. Unspecified documents must resolve
their flavor first. Both throw DocsSectionUnsupportedDocumentFlavorError.
insertColumnBreak(offset: number): booleanParameters
offset— Required. Zero-based data-stream offset at which to insert the column break.
Returns
Whether the insertion succeeded.
Examples
const fDocument = univerAPI.getActiveDocument()if (fDocument?.isTraditional()) { const paragraph = fDocument.findParagraphByText('Continue in next column') const offset = paragraph?.getInfo().startOffset if (offset != null) { fDocument.insertColumnBreak(offset) }}Package: @univerjs/docs · Type definitions
FDocument.insertHorizontalRule
Inserts a horizontal rule using the existing paragraph borderBottom mechanism.
The returned paragraph can be inspected or removed with normal paragraph APIs.
Border width and padding are in points (pt).
insertHorizontalRule(offset: number, border?: IParagraphBorder, segmentId?: string): FDocumentParagraph | nullParameters
offset— Required. Zero-based insertion offset in the selected body segment.border— Optional. Default:{ padding: 5, color: { rgb: '#CDD0D8' }, width: 1, dashStyle: DashStyleType.SOLID, }. Bottom border appearance. Defaults to a solid gray 1 pt line with 5 pt padding.segmentId— Optional. Default:''. Header/footer segment ID, or an empty string for the main body (default).
Returns
The inserted paragraph, or null if insertion fails.
Examples
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument?.findParagraphByText('Summary')const offset = paragraph?.getInfo().startOffsetconst rule = offset == null ? null : fDocument?.insertHorizontalRule(offset)console.log(rule?.getId())Types: FDocumentParagraph · IParagraphBorder
Package: @univerjs/docs · Type definitions
FDocument.insertParagraph
Insert a plain-text paragraph before the paragraph at the given paragraph index.
insertParagraph(index: number, text?: string, segmentId?: string): FDocumentParagraphParameters
index— Required. The zero-based paragraph insertion index.text— Optional. Default:''. The paragraph text. Defaults to an empty paragraph.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The inserted paragraph facade instance.
Examples
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument.insertParagraph(0, 'Document title')paragraph.appendText(' suffix')const headerSegmentId = fDocument.ensurePageHeader()const headerParagraph = fDocument.insertParagraph(0, 'Header title', headerSegmentId)headerParagraph.appendText(' suffix')Types: FDocumentParagraph
Package: @univerjs/docs · Type definitions
FDocument.insertSectionBreak
Inserts a traditional document section break and returns its stable facade.
options configures the section created before the inserted break.
Set options.nextSectionType to control how the existing section after the
break begins. For example, use SectionType.NEXT_PAGE to start a chapter on
a new physical page. Both changes are executed by one command and are
undone or redone together.
The offset must be a top-level document position. To insert a break before a table or block such as a callout, use that object's start offset instead of an offset inside the object.
Modern documents must use ColumnGroup. Unspecified documents must resolve
their flavor first. Both throw DocsSectionUnsupportedDocumentFlavorError.
Numeric layout values in options are in 96-DPI layout pixels.
insertSectionBreak(offset: number, options?: IFDocumentInsertSectionBreakOptions): FDocumentSection | nullParameters
offset— Required. Top-level data-stream offset where the section break is inserted.options— Optional. Default:{}. Section properties and the optional type of the following section.
Returns
The section created before the break, or null when the command rejects the insertion.
Examples
const document = univerAPI.getActiveDocument()if (!document) { throw new Error('No active document')}if (!document.isTraditional()) { throw new Error('Traditional document sections are required')}const chapter = document.findParagraphByText('Chapter 2')if (!chapter) { throw new Error('Chapter heading not found')}// Insert the boundary immediately before the chapter heading. The command// also marks the following section as NEXT_PAGE, so the two model changes// share one undo/redo step.const sectionBeforeChapter = document.insertSectionBreak(chapter.getInfo().startOffset, { nextSectionType: univerAPI.Enum.SectionType.NEXT_PAGE,})if (!sectionBeforeChapter) { throw new Error('The chapter heading is not at a valid top-level offset')}console.log({ insertedSection: sectionBeforeChapter.describe(), chapterSection: document.getSectionAt(chapter.getInfo().startOffset)?.describe(),})Types: FDocumentSection · IFDocumentInsertSectionBreakOptions
Package: @univerjs/docs · Type definitions
FDocument.insertText
Insert plain text at a document body offset.
insertText(index: number, text: string, segmentId?: string): booleanParameters
index— Required. The zero-based insertion offset.text— Required. The plain text to insert.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
true if the edit was applied.
Examples
const fDocument = univerAPI.getActiveDocument()fDocument.insertText(0, 'Hello ')const headerSegmentId = fDocument.ensurePageHeader()fDocument.insertText(0, 'Header text', headerSegmentId)Package: @univerjs/docs · Type definitions
FDocument.isModern
Whether this is a Modern document.
A false result can mean either Traditional or Unspecified. Use
isTraditional() before Traditional-only APIs, or getDocumentFlavor()
when all three states matter.
isModern(): booleanReturns
true only for DocumentFlavor.MODERN.
Examples
const fDocument = univerAPI.getActiveDocument()console.log(fDocument?.isModern())Package: @univerjs/docs · Type definitions
FDocument.isTraditional
Whether this is a Traditional document with Word-compatible physical pagination.
Prefer this positive guard before calling section, column-break, page-setup, or paragraph-pagination APIs.
isTraditional(): booleanReturns
true only for DocumentFlavor.TRADITIONAL.
Examples
const document = univerAPI.getActiveDocument()if (document?.isTraditional()) { console.log(document.getSection(0)?.getEffectivePageSetup())}Package: @univerjs/docs · Type definitions
FDocument.redo
Redo the last undone operation in the document.
redo(): booleanReturns
true if the redo operation was successful, or false if it failed.
Examples
const fDocument = univerAPI.getActiveDocument()const success = fDocument.redo()console.log(success)Package: @univerjs/docs · Type definitions
FDocument.save
Save the document snapshot data, including the document content and resource data, etc.
save(): IDocumentDataReturns
The document snapshot data.
Examples
const fDocument = univerAPI.getActiveDocument()const snapshot = fDocument.save()console.log(snapshot)Types: IDocumentData
Package: @univerjs/docs · Type definitions
FDocument.setHeaderFooterOptions
Updates document-level header/footer switches and margins.
Traditional and Unspecified documents keep the legacy header/footer
behavior. Modern documents reject this API. marginHeader and
marginFooter use 96-DPI layout pixels.
setHeaderFooterOptions(options: IHeaderFooterProps): booleanParameters
options— Required. Header/footer switches and margins to update. Omitted properties are preserved.
Returns
Whether the update command succeeded.
Examples
const fDocument = univerAPI.getActiveDocument()if (fDocument && fDocument.getDocumentFlavor() !== univerAPI.Enum.DocumentFlavor.MODERN) { fDocument.setHeaderFooterOptions({ marginHeader: 36, marginFooter: 36 })}Types: IHeaderFooterProps
Package: @univerjs/docs · Type definitions
FDocument.setName
Set the document name.
setName(name: string): thisParameters
name— Required. The new document name.
Returns
The current document for chaining.
Examples
const document = univerAPI.getActiveDocument()document?.setName('Quarterly Report')Package: @univerjs/docs · Type definitions
FDocument.undo
Undo the last operation in the document.
undo(): booleanReturns
true if the undo operation was successful, or false if it failed.
Examples
const fDocument = univerAPI.getActiveDocument()const success = fDocument.undo()console.log(success)Package: @univerjs/docs · Type definitions
@univerjs/docs-drawing
FDocument.getImage
Gets an image by its drawing id.
getImage(imageId: string): FDocumentImage | nullParameters
imageId— Required. The drawing id of the image.
Returns
The image facade, or null when the image does not exist.
Examples
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImage('image-1')console.log(image)Types: FDocumentImage
Package: @univerjs/docs-drawing · Type definitions
FDocument.getImages
Gets all images in the document in drawing order.
getImages(): FDocumentImage[]Returns
The image facades in drawing order.
Examples
const fDocument = univerAPI.getActiveDocument()const images = fDocument.getImages()console.log(images)Types: FDocumentImage
Package: @univerjs/docs-drawing · Type definitions
FDocument.insertImage
Inserts an image into the document.
When width and height are both omitted, the intrinsic size is proportionally limited to 500 by 500 pixels.
For ordinary content, prefer INLINE, WRAP_SQUARE, or WRAP_TOP_AND_BOTTOM. Use BEHIND_TEXT for
backgrounds or watermarks and IN_FRONT_OF_TEXT only for intentional overlays, because these two styles do not
cause text to reflow.
insertImage(options: IFDocumentInsertImageOptions): Promise<FDocumentImage | null>Parameters
options— Required. The image source, optional transform, and insertion range.
Returns
The inserted image facade, or null when the insertion command fails.
Examples
const fDocument = univerAPI.getActiveDocument()const image = await fDocument.insertImage({ source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', imageSourceType: univerAPI.Enum.ImageSourceType.URL, width: 320, // Keep the image in the text flow so it cannot cover surrounding text. wrappingStyle: univerAPI.Enum.TextWrappingStyle.INLINE, textRange: { startOffset: 30, },})console.log(image)const fDocument = univerAPI.getActiveDocument()const image = await fDocument.insertImage({ source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', imageSourceType: univerAPI.Enum.ImageSourceType.URL, width: 320, // Float the image and let body text flow beside its rectangular bounds. wrappingStyle: univerAPI.Enum.TextWrappingStyle.WRAP_SQUARE, textRange: { startOffset: 30, },})console.log(image)Types: FDocumentImage · Promise · IFDocumentInsertImageOptions
Package: @univerjs/docs-drawing · Type definitions
@univerjs/docs-ui
FDocument.setSelection
Sets the selection to a specified text range in the document. A computed offscreen target is selected after its render data is loaded. A newer pointer/selection action or changed text supersedes that request.
setSelection(startOffset: number, endOffset: number): voidParameters
startOffset— Required. The starting offset of the selection in the document.endOffset— Required. The ending offset of the selection in the document.
Examples
const fDocument = univerAPI.getActiveDocument()fDocument.setSelection(10, 20)Package: @univerjs/docs-ui · Type definitions
@univerjs-pro/docs-callout
FDocument.findCalloutByText
Finds the first callout whose text contains the given string.
findCalloutByText(text: string): FDocumentCallout | nullParameters
text— Required. Text to search inside callout content.
Returns
The first matching FDocumentCallout instance, or null if no match is found.
Examples
const fDocument = univerAPI.getActiveDocument()const callout = fDocument.findCalloutByText('important')console.log(callout)Types: FDocumentCallout
Package: @univerjs-pro/docs-callout · Type definitions
FDocument.findCallouts
Finds callouts by text or block id.
findCallouts(query: string | IDocsCalloutFindQuery): FDocumentCallout[]Parameters
query— Required. A plain text query or a structured callout query.
Returns
An array of matching FDocumentCallout instances, or an empty array if no match is found.
Examples
const fDocument = univerAPI.getActiveDocument()const calloutsWithText = fDocument.findCallouts('important')const calloutsWithId = fDocument.findCallouts({ blockId: 'block-id-123' })console.log(calloutsWithText, calloutsWithId)Types: FDocumentCallout · IDocsCalloutFindQuery
Package: @univerjs-pro/docs-callout · Type definitions
FDocument.getCallout
Returns a callout block range by its block id.
getCallout(blockId: string): FDocumentCallout | nullParameters
blockId— Required. The callout block range id.
Returns
The FDocumentCallout instance, or null if no callout block range with the id exists in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const callout = fDocument.getCallout('block-id-123')console.log(callout)Types: FDocumentCallout
Package: @univerjs-pro/docs-callout · Type definitions
FDocument.getCalloutAt
Returns the callout block range that contains a document data stream offset.
getCalloutAt(offset: number): FDocumentCallout | nullParameters
offset— Required. The document data stream offset.
Returns
The FDocumentCallout instance, or null if no callout block range contains the offset.
Examples
const fDocument = univerAPI.getActiveDocument()const callout = fDocument.getCalloutAt(150)console.log(callout)Types: FDocumentCallout
Package: @univerjs-pro/docs-callout · Type definitions
FDocument.getCallouts
Returns all callout block ranges in this document.
getCallouts(): FDocumentCallout[]Returns
An array of FDocumentCallout instances, or an empty array if no callout block ranges exist in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const callouts = fDocument.getCallouts()console.log(callouts)Types: FDocumentCallout
Package: @univerjs-pro/docs-callout · Type definitions
FDocument.insertCallout
Inserts a callout around a paragraph element.
The paragraph wrapper is resolved by persisted paragraphId before the command runs, so facade edits
inserted before the paragraph do not require recalculating offsets.
This API writes keepLines and widowControl to every inserted paragraph.
For multiple paragraphs it also writes keepNext = TRUE between adjacent
paragraphs and keepNext = FALSE on the final paragraph, so the callout
does not capture the following body paragraph. Callers do not need to add
these pagination styles manually.
Traditional Docs apply the styles during physical pagination. A callout that fits on a fresh page stays together; content taller than a fresh page remains splittable. Modern and Unspecified Docs preserve the styles in the model but do not apply them during physical pagination.
insertCallout(paragraph: FDocumentParagraph, options?: IDocsCalloutInsertParagraphFacadeOptions): FDocumentCallout | nullinsertCallout(options?: IDocsCalloutInsertFacadeOptions): FDocumentCallout | nullParameters
paragraph— Optional. The paragraph to convert to a callout.options— Optional. Optional block id and visual config.
Returns
The inserted FDocumentCallout instance, or null if the insert callout failed.
Examples
const fDocument = univerAPI.getActiveDocument()if (!fDocument) { throw new Error('No active document')}// Insert a callout around a paragraph with the icon config.const paragraph = fDocument.appendParagraph('Remember to review the launch checklist.')const callout = fDocument.insertCallout(paragraph, { config: { icon: '!' },})if (!callout) { throw new Error('Failed to insert the callout')}console.log({ blockId: callout.getId(), wordPaginationApplied: fDocument.isTraditional(),})const fDocument = univerAPI.getActiveDocument()if (!fDocument) { throw new Error('No active document')}// Insert a callout around the text 'Risk' in a table cell with the icon config.const table = fDocument.findTableByText('Risk')const range = table?.getCell(1, 0)?.getContentRange()if (!range) { throw new Error('Risk table cell not found')}const callout = fDocument.insertCallout({ ...range, config: { icon: '!' } })if (!callout) { throw new Error('Failed to insert the table-cell callout')}console.log(callout.getId())// Insert a callout around the text 'Callout' and next paragraph with the icon config.const paragraph = fDocument.findParagraphByText('Callout')if (paragraph) { const paragraphs = fDocument.getParagraphs() const { paragraphIndex, startOffset } = paragraph.getInfo() const finalParagraph = paragraphs[paragraphIndex + 1] if (!finalParagraph) { throw new Error('Expected a paragraph after the callout start') } const { endOffset } = finalParagraph.getInfo() const callout2 = fDocument.insertCallout({ startOffset, endOffset, config: { icon: '!' } }) if (!callout2) { throw new Error('Failed to insert the multi-paragraph callout') } console.log(callout2.getId())}Types: FDocumentCallout · FDocumentParagraph · IDocsCalloutInsertParagraphFacadeOptions · IDocsCalloutInsertFacadeOptions
Package: @univerjs-pro/docs-callout · Type definitions
@univerjs-pro/docs-chart
FDocument.getChart
Returns a Document Chart by its Chart resource id or drawing id.
getChart(chartIdOrDrawingId: string): FDocumentChart | nullParameters
chartIdOrDrawingId— Required. A Chart resource id or Document drawing id.
Returns
The live Document Chart facade, or null if it does not exist.
Examples
const fDocument = univerAPI.getActiveDocument()const fChart = fDocument.getChart('chartIdOrDrawingId')console.log(fChart?.getInfo())Types: FDocumentChart
Package: @univerjs-pro/docs-chart · Type definitions
FDocument.getCharts
Returns all Charts in this Document.
getCharts(): FDocumentChart[]Returns
Live Chart facades in Document drawing order.
Examples
const fDocument = univerAPI.getActiveDocument()const fCharts = fDocument.getCharts()fCharts.forEach((fChart) => { console.log(fChart.getId(), fChart.getDrawingId(), fChart.getInfo())})Types: FDocumentChart
Package: @univerjs-pro/docs-chart · Type definitions
FDocument.insertChart
Inserts a Chart into this Document from detached Chart information.
insertChart(info: IDocumentChartInfo): Promise<FDocumentChart>Parameters
info— Required. The configuration, data source, and layout produced by a Document Chart Builder.
Returns
A live facade for the inserted Document Chart.
Throws
If the data source, insertion anchor, layout, or command is invalid.
Examples
const fDocument = univerAPI.getActiveDocument()const chartInfo = fDocument .newChart(univerAPI.Enum.ChartTypeString.Column) .setSource([ ['Quarter', 'Sales'], ['Q1', 120], ['Q2', 180], ]) .setPosition({ kind: univerAPI.Enum.DocsChartInsertAnchorKind.BodyOffset, offset: 0, }) .setInline() .setSize(640, 360) .build()const fChart = await fDocument.insertChart(chartInfo)fChart.setTitle('Quarterly sales')Types: FDocumentChart · Promise · IDocumentChartInfo
Package: @univerjs-pro/docs-chart · Type definitions
FDocument.newChart
Creates a detached, type-specific Chart Builder for this Document.
newChart<T extends ChartTypeString>(type: T): FDocumentChartBuilderOf<T>Parameters
type— Required. The Chart type to create.
Returns
A detached Builder that produces insertable Document Chart information.
Examples
const fDocument = univerAPI.getActiveDocument()if (!fDocument) throw new Error('No active document.')const chartInfo = fDocument .newChart(univerAPI.Enum.ChartTypeString.Line) .setSource([ ['Month', 'Sales'], ['Jan', 120], ['Feb', 180], ['Mar', 160], ]) .setFloating() .setAbsolutePosition(120, 80) .setSize(640, 360) .setTitle('Monthly sales') .setLineStyle({ width: 2 }) .build()const fChart = await fDocument.insertChart(chartInfo)console.log(fChart.getId(), fChart.getDrawingId())Types: FDocumentChartBuilderOf
Package: @univerjs-pro/docs-chart · Type definitions
@univerjs-pro/docs-code
FDocument.findCodeByText
Finds the first code whose text contains the given string.
findCodeByText(text: string): FDocumentCode | nullParameters
text— Required. Text to search inside code content.
Returns
The first matching FDocumentCode instance, or null if no match is found.
Examples
const fDocument = univerAPI.getActiveDocument()const code = fDocument.findCodeByText('function')console.log(code)Types: FDocumentCode
Package: @univerjs-pro/docs-code · Type definitions
FDocument.findCodes
Finds codes by text or block id.
findCodes(query: string | IDocsCodeFindQuery): FDocumentCode[]Parameters
query— Required. A plain text query or a structured code query.
Returns
An array of matching FDocumentCode instances, or an empty array if no match is found.
Examples
const fDocument = univerAPI.getActiveDocument()const codesWithText = fDocument.findCodes('function')const codesWithId = fDocument.findCodes({ blockId: 'block-id-123' })console.log(codesWithText, codesWithId)Types: FDocumentCode · IDocsCodeFindQuery
Package: @univerjs-pro/docs-code · Type definitions
FDocument.getCode
Returns a code block range by its block id.
getCode(blockId: string): FDocumentCode | nullParameters
blockId— Required. The code block range id.
Returns
The FDocumentCode instance, or null if no code block range with the id exists in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const code = fDocument.getCode('block-id-123')console.log(code)Types: FDocumentCode
Package: @univerjs-pro/docs-code · Type definitions
FDocument.getCodeAt
Returns the code that contains a document data stream offset.
getCodeAt(offset: number): FDocumentCode | nullParameters
offset— Required. The document data stream offset.
Returns
The FDocumentCode instance, or null if no code block range contains the offset.
Examples
const fDocument = univerAPI.getActiveDocument()const code = fDocument.getCodeAt(150)console.log(code)Types: FDocumentCode
Package: @univerjs-pro/docs-code · Type definitions
FDocument.getCodes
Returns all code block ranges in this document.
getCodes(): FDocumentCode[]Returns
An array of FDocumentCode instances, or an empty array if no code block ranges exist in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const codes = fDocument.getCodes()console.log(codes)Types: FDocumentCode
Package: @univerjs-pro/docs-code · Type definitions
FDocument.insertCode
Inserts a code block around a paragraph element.
The paragraph wrapper is resolved by persisted paragraphId before the command runs, so facade edits
inserted before the paragraph do not require recalculating offsets.
This API writes keepLines and widowControl to every inserted paragraph.
For multiple paragraphs it also writes keepNext = TRUE between adjacent
paragraphs and keepNext = FALSE on the final paragraph, so the code block
does not capture the following body paragraph. Callers do not need to add
these pagination styles manually.
Traditional Docs apply the styles during physical pagination. A code block that fits on a fresh page stays together; content taller than a fresh page remains splittable. Modern and Unspecified Docs preserve the styles in the model but do not apply them during physical pagination.
insertCode(paragraph: FDocumentParagraph, options?: IDocsCodeInsertParagraphFacadeOptions): FDocumentCode | nullinsertCode(options?: IDocsCodeInsertFacadeOptions): FDocumentCode | nullParameters
paragraph— Optional. The paragraph to convert to a code block.options— Optional. Optional block id and code config.
Returns
The newly inserted FDocumentCode instance, or null if the insert code failed.
Examples
const fDocument = univerAPI.getActiveDocument()if (!fDocument) { throw new Error('No active document')}// Insert a code block around a paragraph with TypeScript language config.const paragraph = fDocument.appendParagraph('const total = rows.length;')const code = fDocument.insertCode(paragraph, { config: { language: 'typescript' },})if (!code) { throw new Error('Failed to insert the code block')}console.log({ language: code.getConfig()?.language, wordPaginationApplied: fDocument.isTraditional(),})const fDocument = univerAPI.getActiveDocument()if (!fDocument) { throw new Error('No active document')}// Insert a code block around the text "Snippet" in a table cell with TypeScript language config.const table = fDocument.findTableByText('Snippet')const range = table?.getCell(1, 0)?.getContentRange()if (!range) { throw new Error('Snippet table cell not found')}const code = fDocument.insertCode({ ...range, config: { language: 'typescript' } })if (!code) { throw new Error('Failed to insert the table-cell code block')}console.log(code.getId())// Insert a code block around the text "const" and the next three paragraphs with TypeScript language config.// const cell = {// width: 960,// blocks: ['code', 'callout', 'quote']// };const paragraph = fDocument.findParagraphByText('const')if (paragraph) { const paragraphs = fDocument.getParagraphs() const { paragraphIndex, startOffset } = paragraph.getInfo() const finalParagraph = paragraphs[paragraphIndex + 3] if (!finalParagraph) { throw new Error('Expected three paragraphs after the code start') } const { endOffset } = finalParagraph.getInfo() const code2 = fDocument.insertCode({ startOffset, endOffset, config: { language: 'typescript' } }) if (!code2) { throw new Error('Failed to insert the multi-paragraph code block') } console.log(code2.getId())}Types: FDocumentCode · FDocumentParagraph · IDocsCodeInsertParagraphFacadeOptions · IDocsCodeInsertFacadeOptions
Package: @univerjs-pro/docs-code · Type definitions
@univerjs-pro/docs-column
FDocument.findColumnGroupByText
Finds the first column group that contains a column with matching text.
findColumnGroupByText(text: string): FDocumentColumnGroup | nullParameters
text— Required. Plain text to search inside columns.
Returns
The first matching column group, or null when no group contains the text.
Examples
const fDocument = univerAPI.getActiveDocument()const group = fDocument.findColumnGroupByText('Launch')console.log(group?.describe())Types: FDocumentColumnGroup
Package: @univerjs-pro/docs-column · Type definitions
FDocument.findColumnGroups
Finds column groups by text or by id.
findColumnGroups(query: string | IDocsColumnFindQuery): FDocumentColumnGroup[]Parameters
query— Required. Plain text to search inside columns, or a structured query.
Returns
Matching column groups in document order.
Examples
const fDocument = univerAPI.getActiveDocument()const groupsWithText = fDocument.findColumnGroups('Launch')const groupsWithId = fDocument.findColumnGroups({ columnGroupId: 'column-group-1' })console.log(groupsWithText, groupsWithId)Types: FDocumentColumnGroup · IDocsColumnFindQuery
Package: @univerjs-pro/docs-column · Type definitions
FDocument.getColumnGroup
Returns a column group by id.
getColumnGroup(columnGroupId: string): FDocumentColumnGroup | nullParameters
columnGroupId— Required. The column group id stored inbody.columnGroups.
Returns
The column group wrapper, or null if no group has the id.
Examples
const fDocument = univerAPI.getActiveDocument()const group = fDocument.getColumnGroup('column-group-1')console.log(group?.describe())Types: FDocumentColumnGroup
Package: @univerjs-pro/docs-column · Type definitions
FDocument.getColumnGroupAt
Returns the column group that contains a data-stream offset.
getColumnGroupAt(offset: number): FDocumentColumnGroup | nullParameters
offset— Required. Zero-based document body data-stream offset.
Returns
The containing column group, or null when the offset is outside all groups.
Examples
const fDocument = univerAPI.getActiveDocument()const group = fDocument.getColumnGroupAt(128)console.log(group?.describe())Types: FDocumentColumnGroup
Package: @univerjs-pro/docs-column · Type definitions
FDocument.getColumnGroups
Returns all column groups in this document.
getColumnGroups(): FDocumentColumnGroup[]Returns
Column group wrappers, or an empty array when the document has no column groups.
Examples
const fDocument = univerAPI.getActiveDocument()const groups = fDocument.getColumnGroups()console.log(groups.map((group) => group.describe()))Types: FDocumentColumnGroup
Package: @univerjs-pro/docs-column · Type definitions
FDocument.insertColumnGroup
Inserts an empty column group into the document.
By default the group is inserted before the final body section break. Pass offset
when you need to insert at a specific data-stream position. Every inserted column
contains an editable empty paragraph. Column groups are supported only in modern
documents; traditional documents throw DocsColumnUnsupportedDocumentFlavorError.
insertColumnGroup(columnCount: number, options?: IDocsColumnInsertFacadeOptions): FDocumentColumnGroup | nullParameters
columnCount— Required. Number of columns to create. Values below two are normalized to two; values above five fail.options— Optional. Default:{}. Optional id, column ids, insertion offset, gap, and initial width ratios.
Returns
The inserted column group wrapper, or null if insertion failed.
Examples
const fDocument = univerAPI.getActiveDocument()const group = fDocument.insertColumnGroup(3, { gap: 18, widthRatios: [1.1, 1, 0.9],})const [left, middle, right] = group?.getColumns() ?? []const leftOffset = left?.getInsertOffset()if (leftOffset != null) { fDocument.insertText(leftOffset, 'Editorial brief\rUse columns for compact narrative layout.')}const middleOffset = middle?.getInsertOffset()if (middleOffset != null) { fDocument.insertText(middleOffset, 'Production checklist\rDrag content into this column.')}const rightOffset = right?.getInsertOffset()if (rightOffset != null) { fDocument.insertTableFromData( [ ['Metric', 'Now', 'Next'], ['Adoption', '68%', '80%'], ['Quality', 'A-', 'A'], ], { offset: rightOffset, headerRowCount: 1, }, )}console.log(group?.describe())Types: FDocumentColumnGroup · IDocsColumnInsertFacadeOptions
Package: @univerjs-pro/docs-column · Type definitions
@univerjs-pro/docs-formula
FDocument.getFormula
Resolves one complete Doc Formula by stable rangeId.
getFormula(rangeId: string): FDocumentFormula | nullParameters
rangeId— Required. Identity returned by insertion orFDocumentFormula.getId.
Returns
A handle, or null when either the range or Resource entry is absent.
Examples
import type { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/docs-formula/facade'export function getDocFormula(univerAPI: FUniver, rangeId: string) { const document = univerAPI.getActiveDocument() if (!document) throw new Error('No active document') const formula = document.getFormula(rangeId) if (!formula) throw new Error(`Doc Formula ${rangeId} was not found`) return formula}Types: FDocumentFormula
Package: @univerjs-pro/docs-formula · Type definitions
FDocument.getFormulaAt
Resolves the whole-entity Doc Formula containing a main-body offset.
getFormulaAt(offset: number): FDocumentFormula | nullParameters
offset— Required. Document data-stream offset.
Returns
A handle, or null when the offset is not a complete Doc Formula.
Examples
import type { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/docs-formula/facade'export function getDocFormulaAt(univerAPI: FUniver, offset: number) { const document = univerAPI.getActiveDocument() if (!document) throw new Error('No active document') return document.getFormulaAt(offset)}Types: FDocumentFormula
Package: @univerjs-pro/docs-formula · Type definitions
FDocument.getFormulas
Lists complete Formula custom-range/Resource pairs in the main body.
Incomplete or unsupported persisted data remains preserved by the core plugin but is intentionally omitted from calculation and this list.
getFormulas(): FDocumentFormula[]Returns
Formula handles in document order, or an empty array.
Examples
import type { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/docs-formula/facade'export function listDocFormulas(univerAPI: FUniver) { const document = univerAPI.getActiveDocument() if (!document) throw new Error('No active document') return document.getFormulas().map((formula) => formula.describe())}Types: FDocumentFormula
Package: @univerjs-pro/docs-formula · Type definitions
FDocument.insertFormula
Replaces an explicit main-body range with one inline Doc Formula.
The offsets are snapshot-relative and resolved immediately. This API is
suitable when the caller already owns a current range in the same
synchronous workflow. Agent and delayed headless workflows should prefer
a stable FDocumentParagraph handle with insertFormula() or
appendFormula().
The Command validates the range, formula syntax, and complete external Source bindings before it commits TextX, Host External Reference, and Doc Formula Resource mutations as one undoable user action.
insertFormula(options: IDocFormulaInsertFacadeOptions): FDocumentFormula | nullParameters
options— Required. Formula, half-open replacement range, number format, and any stable external Source bindings.
Returns
The inserted handle, or null if validation or a mutation fails.
Examples
import type { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/docs-formula/facade'export function insertConstantFormula(univerAPI: FUniver) { const document = univerAPI.getActiveDocument() if (!document) throw new Error('No active document') const formula = document.insertFormula({ formula: '=1+2', startOffset: 0, endOffset: 0, numberFormat: { pattern: '0.00' }, }) if (!formula) throw new Error('Doc Formula insertion failed') return formula.getId()}import { UniverInstanceType } from '@univerjs/core'import type { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/docs-formula/facade'export function insertBoundFormula(univerAPI: FUniver) { const document = univerAPI.getActiveDocument() if (!document) throw new Error('No active document') const formula = document.insertFormula({ formula: "='[Sales Source]Data'!A1", startOffset: 0, endOffset: 0, externalReferences: [ { qualifier: 'Sales Source', sourceUnitId: 'sales-source-v1', sourceUnitType: UniverInstanceType.UNIVER_SHEET, }, ], }) if (!formula) throw new Error('Source binding or range was invalid') return formula.getId()}Types: FDocumentFormula · IDocFormulaInsertFacadeOptions
Package: @univerjs-pro/docs-formula · Type definitions
FDocument.saveFormulaDisplayTextSnapshot
Saves a detached external-format projection of this document.
Native save() preserves Formula custom ranges and Resource entries.
This method instead replaces every main-body Doc Formula object with its
persisted lastValue display text and removes the Doc Formula Resource from
the returned snapshot. It never mutates the live document and is intended
for Markdown, HTML, TXT, DOCX, and other non-native exporters.
Export never triggers calculation, waits for a result, or reads the
current in-memory presentation. The last successful persisted value is
emitted with its inherited or explicit number format. A missing or empty
lastValue becomes an empty string; U+FFFC is never returned.
saveFormulaDisplayTextSnapshot(): IDocumentDataReturns
A detached IDocumentData projection safe for external export.
Examples
import type { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/docs-formula/facade'export function saveForExternalExporter(univerAPI: FUniver) { const document = univerAPI.getActiveDocument() if (!document) throw new Error('No active document') const snapshot = document.saveFormulaDisplayTextSnapshot() if (snapshot.body?.dataStream.includes('\uFFFC')) { throw new Error('External snapshot contains an object token') } return snapshot}Types: IDocumentData
Package: @univerjs-pro/docs-formula · Type definitions
@univerjs-pro/docs-latex
FDocument.findLatexFormulaByText
Finds the first LaTeX formula whose source contains the given text.
findLatexFormulaByText(latex: string, segmentId?: string): FDocumentLatex | nullParameters
latex— Required. Text to search for inside formula source.segmentId— Optional. Default:''. Header/footer segment id. Omit it for the main document body.
Returns
The first matching formula, or null if no match is found.
Examples
const univerAPI = FUniver.newAPI(univer)const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active document')const existing = document.getLatexFormulas()[0]if (!existing) throw new Error('No LaTeX formula')const formula = document.findLatexFormulaByText(existing.getLatex())if (!formula) throw new Error('Cannot find LaTeX formula by text')console.log(formula.getRange())Types: FDocumentLatex
Package: @univerjs-pro/docs-latex · Type definitions
FDocument.findLatexFormulas
Finds LaTeX formulas by source text or range id.
findLatexFormulas(query: string | IDocsLatexFindQuery, segmentId?: string): FDocumentLatex[]Parameters
query— Required. A source-text query or a structured query.segmentId— Optional. Default:''. Header/footer segment id. Omit it for the main document body.
Returns
Matching formula facade objects, or an empty array if no match is found.
Examples
const univerAPI = FUniver.newAPI(univer)const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active document')const existing = document.getLatexFormulas()[0]if (!existing) throw new Error('No LaTeX formula')const byText = document.findLatexFormulas(existing.getLatex())const byId = document.findLatexFormulas({ rangeId: existing.getId() })console.log(byText, byId)Types: FDocumentLatex · IDocsLatexFindQuery
Package: @univerjs-pro/docs-latex · Type definitions
FDocument.getLatexFormula
Returns a LaTeX formula by its range id.
getLatexFormula(rangeId: string, segmentId?: string): FDocumentLatex | nullParameters
rangeId— Required. The formula custom range id.segmentId— Optional. Default:''. Header/footer segment id. Omit it for the main document body.
Returns
The matching formula facade object, or null if no formula has that id.
Examples
const univerAPI = FUniver.newAPI(univer)const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active document')const existing = document.getLatexFormulas()[0]if (!existing) throw new Error('No LaTeX formula')const formula = document.getLatexFormula(existing.getId())if (!formula) throw new Error('Cannot find LaTeX formula by id')console.log(formula.describe())Types: FDocumentLatex
Package: @univerjs-pro/docs-latex · Type definitions
FDocument.getLatexFormulaAt
Returns the LaTeX formula that contains a document data-stream offset.
getLatexFormulaAt(offset: number, segmentId?: string): FDocumentLatex | nullParameters
offset— Required. The document data-stream offset.segmentId— Optional. Default:''. Header/footer segment id. Omit it for the main document body.
Returns
The formula at the offset, or null if the offset is not inside a formula.
Examples
const univerAPI = FUniver.newAPI(univer)const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active document')const existing = document.getLatexFormulas()[0]if (!existing) throw new Error('No LaTeX formula')const range = existing.getRange()if (!range) throw new Error('LaTeX formula has no range')const formula = document.getLatexFormulaAt(range.startOffset)if (!formula) throw new Error('Cannot find LaTeX formula at offset')console.log(formula.getLatex())Types: FDocumentLatex
Package: @univerjs-pro/docs-latex · Type definitions
FDocument.getLatexFormulas
Returns all LaTeX formulas in this document.
getLatexFormulas(segmentId?: string): FDocumentLatex[]Parameters
segmentId— Optional. Default:''. Header/footer segment id. Omit it for the main document body.
Returns
An array of formula facade objects, or an empty array if the document has none.
Examples
const univerAPI = FUniver.newAPI(univer)const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active document')const formulas = document.getLatexFormulas()console.log(formulas.map((formula) => formula.getLatex()))Types: FDocumentLatex
Package: @univerjs-pro/docs-latex · Type definitions
FDocument.insertLatexAtOffset
Inserts a LaTeX formula at an explicit document offset.
This is a low-level API. Agent-authored code should prefer
FDocumentParagraph.appendLatex or FDocumentTextRange.replaceWithLatex.
insertLatexAtOffset(offset: number, latex: string, options?: IDocsLatexCreateFacadeOptions & { segmentId?: string; }): FDocumentLatex | nullParameters
offset— Required. Inclusive insertion offset.latex— Required. LaTeX source without$or$$delimiters.options— Optional. Default:{}. Segment and visual properties.
Returns
The inserted formula, or null when the command fails.
Examples
const univerAPI = FUniver.newAPI(univer)const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active document')const paragraph = document.appendParagraph('Energy: ')const formula = document.insertLatexAtOffset(paragraph.getInfo().endOffset, 'E = mc^2')if (!formula) throw new Error('Failed to insert LaTeX formula')console.log(formula.describe())Types: FDocumentLatex · IDocsLatexCreateFacadeOptions
Package: @univerjs-pro/docs-latex · Type definitions
FDocument.insertLatexAtSelection
Inserts or replaces a LaTeX formula at the active editor selection.
This UI-selection API is not suitable for headless runtimes.
insertLatexAtSelection(latex: string, options?: IDocsLatexCreateFacadeOptions): FDocumentLatex | nullParameters
latex— Required. LaTeX source without$or$$delimiters.options— Optional. Default:{}. Optional visual properties.
Returns
The inserted formula, or null when no valid selection exists.
Examples
const univerAPI = FUniver.newAPI(univer)const document = univerAPI.getActiveDocument()if (!document) throw new Error('No active document')// The user must first select text in the active Docs editor.const formula = document.insertLatexAtSelection('F = ma')if (!formula) { throw new Error('No valid Docs selection, or the insertion failed')}console.log(formula.describe())Types: FDocumentLatex · IDocsLatexCreateFacadeOptions
Package: @univerjs-pro/docs-latex · Type definitions
@univerjs-pro/docs-list
FDocument.describeListItems
Returns agent-friendly list item descriptions in this document body or header/footer body by the segment id.
describeListItems(segmentId?: string): IDocsListItemInfo[]Parameters
segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
An array of list item info objects, or an empty array if no list items exist in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const listItemInfos = fDocument.describeListItems()console.log(listItemInfos)const headerSegmentId = fDocument.ensurePageHeader()const headerListItemInfos = fDocument.describeListItems(headerSegmentId)console.log(headerListItemInfos)const footerSegmentId = fDocument.ensurePageFooter()const footerListItemInfos = fDocument.describeListItems(footerSegmentId)console.log(footerListItemInfos)Types: IDocsListItemInfo
Package: @univerjs-pro/docs-list · Type definitions
FDocument.findListItemByText
Finds the first list item in this document body or header/footer body that contains the given text.
findListItemByText(text: string, segmentId?: string): FDocumentListItem | nullParameters
text— Required. Text to search inside list item content.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The first matching FDocumentListItem instance, or null if no match is found.
Examples
const fDocument = univerAPI.getActiveDocument()const listItem = fDocument.findListItemByText('Ship API')console.log(listItem)const headerSegmentId = fDocument.ensurePageHeader()const headerListItem = fDocument.findListItemByText('Ship API', headerSegmentId)console.log(headerListItem)const footerSegmentId = fDocument.ensurePageFooter()const footerListItem = fDocument.findListItemByText('Ship API', footerSegmentId)console.log(footerListItem)Types: FDocumentListItem
Package: @univerjs-pro/docs-list · Type definitions
FDocument.findListItems
Finds list items in this document body or header/footer body that match the given query.
findListItems(query: string | IDocsListFindQuery, segmentId?: string): FDocumentListItem[]Parameters
query— Required. A plain text query or a structured list item query.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
An array of matching FDocumentListItem instances, or an empty array if no match is found.
Examples
const fDocument = univerAPI.getActiveDocument()const listItems = fDocument.findListItems({ text: 'API', nestingLevel: 2 })console.log(listItems)const headerSegmentId = fDocument.ensurePageHeader()const headerListItems = fDocument.findListItems({ text: 'API', nestingLevel: 2 }, headerSegmentId)console.log(headerListItems)const footerSegmentId = fDocument.ensurePageFooter()const footerListItems = fDocument.findListItems({ text: 'API', nestingLevel: 2 }, footerSegmentId)console.log(footerListItems)Types: FDocumentListItem · IDocsListFindQuery
Package: @univerjs-pro/docs-list · Type definitions
FDocument.getList
Returns a list in this document body or header/footer body by the list id and segment id.
getList(listId: string, segmentId?: string): FDocumentList | nullParameters
listId— Required. The list id stored on paragraph bullets.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The FDocumentList instance, or null if no list with the id exists in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const list = fDocument.getList('list-id-123')console.log(list)const headerSegmentId = fDocument.ensurePageHeader()const headerList = fDocument.getList('list-id-123', headerSegmentId)console.log(headerList)const footerSegmentId = fDocument.ensurePageFooter()const footerList = fDocument.getList('list-id-123', footerSegmentId)console.log(footerList)Types: FDocumentList
Package: @univerjs-pro/docs-list · Type definitions
FDocument.getListItem
Returns a list item in this document body or header/footer body by the paragraph start index and segment id.
getListItem(paragraphStartIndex: number, segmentId?: string): FDocumentListItem | nullParameters
paragraphStartIndex— Required. The paragraph start index that identifies a list item.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The FDocumentListItem instance, or null if no list item with the paragraph start index exists in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const listItem = fDocument.getListItem(10)console.log(listItem)const headerSegmentId = fDocument.ensurePageHeader()const headerListItem = fDocument.getListItem(10, headerSegmentId)console.log(headerListItem)const footerSegmentId = fDocument.ensurePageFooter()const footerListItem = fDocument.getListItem(10, footerSegmentId)console.log(footerListItem)Types: FDocumentListItem
Package: @univerjs-pro/docs-list · Type definitions
FDocument.getListItemAt
Returns the list item in this document body or header/footer body that contains the given offset.
getListItemAt(offset: number, segmentId?: string): FDocumentListItem | nullParameters
offset— Required. The document data stream offset.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The FDocumentListItem instance, or null if no list item contains the offset.
Examples
const fDocument = univerAPI.getActiveDocument()const listItem = fDocument.getListItemAt(150)console.log(listItem)const headerSegmentId = fDocument.ensurePageHeader()const headerListItem = fDocument.getListItemAt(150, headerSegmentId)console.log(headerListItem)const footerSegmentId = fDocument.ensurePageFooter()const footerListItem = fDocument.getListItemAt(150, footerSegmentId)console.log(footerListItem)Types: FDocumentListItem
Package: @univerjs-pro/docs-list · Type definitions
FDocument.getListItems
Returns all list items in this document body or header/footer body by the segment id.
getListItems(segmentId?: string): FDocumentListItem[]Parameters
segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
An array of FDocumentListItem instances, or an empty array if no list items exist in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const listItems = fDocument.getListItems()console.log(listItems)const headerSegmentId = fDocument.ensurePageHeader()const headerListItems = fDocument.getListItems(headerSegmentId)console.log(headerListItems)const footerSegmentId = fDocument.ensurePageFooter()const footerListItems = fDocument.getListItems(footerSegmentId)console.log(footerListItems)Types: FDocumentListItem
Package: @univerjs-pro/docs-list · Type definitions
FDocument.getLists
Returns all docs lists in this document body or header/footer body by the segment id.
getLists(segmentId?: string): FDocumentList[]Parameters
segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
An array of FDocumentList instances.
Examples
const fDocument = univerAPI.getActiveDocument()const lists = fDocument.getLists()console.log(lists)const headerSegmentId = fDocument.ensurePageHeader()const headerLists = fDocument.getLists(headerSegmentId)console.log(headerLists)const footerSegmentId = fDocument.ensurePageFooter()const footerLists = fDocument.getLists(footerSegmentId)console.log(footerLists)Types: FDocumentList
Package: @univerjs-pro/docs-list · Type definitions
FDocument.insertList
Applies list formatting to a paragraph element in this document body or header/footer body.
The paragraph wrapper is resolved by persisted paragraphId before the command runs, so facade edits
inserted before the paragraph do not require recalculating offsets.
insertList(paragraph: FDocumentParagraph, options?: IDocsListInsertParagraphFacadeOptions): FDocumentList | nullinsertList(options?: IDocsListInsertFacadeOptions): FDocumentList | nullParameters
paragraph— Optional. The paragraph to convert to a list item.options— Optional. Optional list type.
Returns
The inserted list facade, or null if the insert list command failed.
Examples
const fDocument = univerAPI.getActiveDocument()// Insert a bullet list around a paragraph with the default list type.const paragraph = fDocument.appendParagraph('Ship docs facade examples')const list = fDocument.insertList(paragraph, { listType: univerAPI.Enum.PresetListType.BULLET_LIST,})console.log(list.describe())// Insert an ordered list around a paragraph in the header and footer with different list types.const headerSegmentId = fDocument.ensurePageHeader()const headerParagraph = fDocument.appendParagraph('Header list item', headerSegmentId)const headerList = fDocument.insertList(headerParagraph, { listType: univerAPI.Enum.PresetListType.ORDER_LIST,})console.log(headerList.describe())const footerSegmentId = fDocument.ensurePageFooter()const footerParagraph = fDocument.appendParagraph('Footer list item', footerSegmentId)const footerList = fDocument.insertList(footerParagraph, { listType: univerAPI.Enum.PresetListType.ORDER_LIST_2,})console.log(footerList.describe())const fDocument = univerAPI.getActiveDocument()// Insert a bullet list in a table cell range with the default list type.const table = fDocument.findTableByText('Revenue')const range = table?.getCell(1, 0)?.getContentRange()if (range) { const list = fDocument.insertList({ ...range, listType: univerAPI.Enum.PresetListType.BULLET_LIST, }) console.log(list.describe())}const paragraph = fDocument.findParagraphByText('List item 1')if (paragraph) { const paragraphs = fDocument.getParagraphs() const { paragraphIndex, startOffset } = paragraph.getInfo() const { endOffset } = paragraphs[paragraphIndex + 3].getInfo() const list2 = fDocument.insertList({ startOffset, endOffset, listType: univerAPI.Enum.PresetListType.BULLET_LIST, }) console.log(list2.describe())}// Insert a list in the page footer by passing the footer segment id.const footerSegmentId = fDocument.ensurePageFooter()const footerList = fDocument.insertList({ startOffset: 0, endOffset: 20, segmentId: footerSegmentId, listType: univerAPI.Enum.PresetListType.ORDER_LIST,})console.log(footerList.describe())Types: FDocumentList · FDocumentParagraph · IDocsListInsertParagraphFacadeOptions · IDocsListInsertFacadeOptions
Package: @univerjs-pro/docs-list · Type definitions
FDocument.setBullet
Agent-friendly shorthand for applying a bullet list to a paragraph.
setBullet(paragraph: FDocumentParagraph, options?: Omit<IDocsListInsertParagraphFacadeOptions, 'listType'>): FDocumentList | nullParameters
paragraph— Required.options— Optional. Default:{}.
Types: FDocumentList · FDocumentParagraph · Omit · IDocsListInsertParagraphFacadeOptions
Package: @univerjs-pro/docs-list · Type definitions
FDocument.setOrderedList
Agent-friendly shorthand for applying an ordered list to a paragraph.
setOrderedList(paragraph: FDocumentParagraph, options?: Omit<IDocsListInsertParagraphFacadeOptions, 'listType'>): FDocumentList | nullParameters
paragraph— Required.options— Optional. Default:{}.
Types: FDocumentList · FDocumentParagraph · Omit · IDocsListInsertParagraphFacadeOptions
Package: @univerjs-pro/docs-list · Type definitions
@univerjs-pro/docs-quote
FDocument.findQuoteByText
Finds the first quote whose text contains the given string.
findQuoteByText(text: string): FDocumentQuote | nullParameters
text— Required. Text to search inside quote content.
Returns
The first matching FDocumentQuote instance, or null if no match is found.
Examples
const fDocument = univerAPI.getActiveDocument()const quote = fDocument.findQuoteByText('Decision')console.log(quote)Types: FDocumentQuote
Package: @univerjs-pro/docs-quote · Type definitions
FDocument.findQuotes
Finds quotes by text or block id.
findQuotes(query: string | IDocsQuoteFindQuery): FDocumentQuote[]Parameters
query— Required. A plain text query or a structured quote query.
Returns
An array of matching FDocumentQuote instances, or an empty array if no match is found.
Examples
const fDocument = univerAPI.getActiveDocument()const quotesWithText = fDocument.findQuotes('Decision')const quotesWithId = fDocument.findQuotes({ blockId: 'block-id-123' })console.log(quotesWithText, quotesWithId)Types: FDocumentQuote · IDocsQuoteFindQuery
Package: @univerjs-pro/docs-quote · Type definitions
FDocument.getQuote
Returns a quote block range by its block id.
getQuote(blockId: string): FDocumentQuote | nullParameters
blockId— Required. The quote block range id.
Returns
The FDocumentQuote instance, or null if no quote block range with the id exists in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const quote = fDocument.getQuote('block-id-123')console.log(quote)Types: FDocumentQuote
Package: @univerjs-pro/docs-quote · Type definitions
FDocument.getQuoteAt
Returns the quote block range that contains a document data stream offset.
getQuoteAt(offset: number): FDocumentQuote | nullParameters
offset— Required. The document data stream offset.
Returns
The FDocumentQuote instance, or null if no quote block range contains the offset.
Examples
const fDocument = univerAPI.getActiveDocument()const quote = fDocument.getQuoteAt(150)console.log(quote)Types: FDocumentQuote
Package: @univerjs-pro/docs-quote · Type definitions
FDocument.getQuotes
Returns all quote block ranges in this document.
getQuotes(): FDocumentQuote[]Returns
An array of FDocumentQuote instances, or an empty array if no quote block ranges exist in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const quotes = fDocument.getQuotes()console.log(quotes)Types: FDocumentQuote
Package: @univerjs-pro/docs-quote · Type definitions
FDocument.insertQuote
Inserts a quote around a paragraph element.
The paragraph wrapper is resolved by persisted paragraphId before the command runs, so facade edits
inserted before the paragraph do not require recalculating offsets.
This API writes keepLines and widowControl to every inserted paragraph.
For multiple paragraphs it also writes keepNext = TRUE between adjacent
paragraphs and keepNext = FALSE on the final paragraph, so the quote does
not capture the following body paragraph. Callers do not need to add these
pagination styles manually.
Traditional Docs apply the styles during physical pagination. A quote that fits on a fresh page stays together; content taller than a fresh page remains splittable. Modern and Unspecified Docs preserve the styles in the model but do not apply them during physical pagination.
insertQuote(paragraph: FDocumentParagraph, options?: IDocsQuoteInsertParagraphFacadeOptions): FDocumentQuote | nullinsertQuote(options?: IDocsQuoteInsertFacadeOptions): FDocumentQuote | nullParameters
paragraph— Optional. The paragraph to convert to a quote.options— Optional. Optional block id.
Returns
The inserted FDocumentQuote instance, or null if the insert quote failed.
Examples
const fDocument = univerAPI.getActiveDocument()if (!fDocument) { throw new Error('No active document')}// Insert a quote around a paragraph.const paragraph = fDocument.appendParagraph('Simplicity is prerequisite for reliability.')const quote = fDocument.insertQuote(paragraph)if (!quote) { throw new Error('Failed to insert the quote')}console.log({ text: quote.getText(), wordPaginationApplied: fDocument.isTraditional(),})const fDocument = univerAPI.getActiveDocument()if (!fDocument) { throw new Error('No active document')}// Insert a quote around the text 'Decision' in a table cell.const table = fDocument.findTableByText('Decision')const range = table?.getCell(1, 0)?.getContentRange()if (!range) { throw new Error('Decision table cell not found')}const quote = fDocument.insertQuote(range)if (!quote) { throw new Error('Failed to insert the table-cell quote')}console.log(quote.getId())// Insert a quote around the text 'Quote' and the next paragraph.const paragraph = fDocument.findParagraphByText('Quote')if (paragraph) { const paragraphs = fDocument.getParagraphs() const { paragraphIndex, startOffset } = paragraph.getInfo() const finalParagraph = paragraphs[paragraphIndex + 1] if (!finalParagraph) { throw new Error('Expected a paragraph after the quote start') } const { endOffset } = finalParagraph.getInfo() const quote2 = fDocument.insertQuote({ startOffset, endOffset }) if (!quote2) { throw new Error('Failed to insert the multi-paragraph quote') } console.log(quote2.getId())}Types: FDocumentQuote · FDocumentParagraph · IDocsQuoteInsertParagraphFacadeOptions · IDocsQuoteInsertFacadeOptions
Package: @univerjs-pro/docs-quote · Type definitions
@univerjs-pro/docs-reference
FDocument.deleteEndnote
Removes an endnote and its body reference; supports undo and collaboration.
deleteEndnote(noteId: string): booleanParameters
noteId— Required. Stable endnote segment id.
Returns
Whether deletion succeeded.
Examples
const document = univerAPI.getActiveDocument()const note = document?.getEndnotes()[0]if (note) document.deleteEndnote(note.noteId)Package: @univerjs-pro/docs-reference · Type definitions
FDocument.deleteFootnote
Removes a footnote together with its body reference. Supports undo and collaboration.
deleteFootnote(noteId: string): booleanParameters
noteId— Required. Stable segment id returned by insertFootnote or getFootnotes.
Returns
Whether the deletion was applied.
Examples
const document = univerAPI.getActiveDocument()const note = document?.getFootnotes()[0]if (note) document.deleteFootnote(note.noteId)Package: @univerjs-pro/docs-reference · Type definitions
FDocument.getEndnotes
Returns detached endnotes in body reference order.
getEndnotes(): IDocumentNote[]Returns
Endnote data.
Examples
console.log(univerAPI.getActiveDocument()?.getEndnotes())Types: IDocumentNote
Package: @univerjs-pro/docs-reference · Type definitions
FDocument.getEndnoteSettings
Returns explicit document settings or section overrides.
getEndnoteSettings(sectionId?: string): IEndnoteSettings | undefinedParameters
sectionId— Optional. Optional section id.
Returns
Detached explicit settings.
Examples
console.log(univerAPI.getActiveDocument()?.getEndnoteSettings())Types: IEndnoteSettings
Package: @univerjs-pro/docs-reference · Type definitions
FDocument.getFootnotes
Returns detached note data in reference order. Automatic labels depend on layout when numbering restarts on each page; the persisted segment id remains stable.
getFootnotes(): IDocumentNote[]Returns
Notes referenced by the main body.
Examples
console.log(univerAPI.getActiveDocument()?.getFootnotes())Types: IDocumentNote
Package: @univerjs-pro/docs-reference · Type definitions
FDocument.getFootnoteSettings
Reads explicit document defaults or a section override, without expanding inherited values.
getFootnoteSettings(sectionId?: string): IFootnoteSettings | undefinedParameters
sectionId— Optional. Optional stable section id.
Returns
Detached explicit settings, or undefined if absent.
Examples
console.log(univerAPI.getActiveDocument()?.getFootnoteSettings())Types: IFootnoteSettings
Package: @univerjs-pro/docs-reference · Type definitions
FDocument.insertEndnote
Inserts an endnote with its body reference as one undoable change.
insertEndnote(offset: number, content?: Partial<Omit<IDocumentNote, 'noteId' | 'type'>>): string | nullParameters
offset— Required. UTF-16 body offset.content— Optional. Default:{}. Optional rich content and custom mark.
Returns
Stable note segment id, or null when insertion is rejected.
Examples
const id = univerAPI.getActiveDocument()?.insertEndnote(5)Types: Partial · Omit · IDocumentNote
Package: @univerjs-pro/docs-reference · Type definitions
FDocument.insertFootnote
Inserts a traditional-document footnote at a UTF-16 body offset and selects its content. The reference and rich content share one undo/collaboration mutation. Returns null for a modern document, an invalid position/content, or insufficient edit permission.
insertFootnote(offset: number, content?: Partial<Omit<IDocumentNote, 'noteId' | 'type'>>): string | nullParameters
offset— Required. Position in the main body, including structural tokens.content— Optional. Default:{}. Optional paragraphs, inline drawings, tables and custom mark.
Returns
Stable segment id, usable with getTextRange and getParagraphs.
Examples
const document = univerAPI.getActiveDocument()const id = document?.insertFootnote(5, { body: { dataStream: 'Source details\r\n', paragraphs: [{ startIndex: 14 }] },})if (id) console.log(document.getParagraphs(id))Types: Partial · Omit · IDocumentNote
Package: @univerjs-pro/docs-reference · Type definitions
FDocument.setEndnoteSettings
Replaces endnote settings; null restores inherited defaults.
setEndnoteSettings(settings: IEndnoteSettings | null, sectionId?: string): booleanParameters
settings— Required. Endnote settings or null.sectionId— Optional. Optional section id.
Returns
Whether settings changed.
Examples
univerAPI.getActiveDocument()?.setEndnoteSettings({ position: 'sectEnd', restart: 'eachSect' })Types: IEndnoteSettings
Package: @univerjs-pro/docs-reference · Type definitions
FDocument.setFootnoteSettings
Replaces explicit footnote settings; null restores inherited defaults. Section overrides support position, columns and numbering. Separator bodies belong to document defaults.
setFootnoteSettings(settings: IFootnoteSettings | null, sectionId?: string): booleanParameters
settings— Required. Replacement settings or null to reset.sectionId— Optional. Optional stable section id.
Returns
Whether the settings changed.
Examples
univerAPI.getActiveDocument()?.setFootnoteSettings({ position: 'pageBottom', columnCount: 2, numberFormat: 'decimal', startNumber: 1, restart: 'eachSect',})Types: IFootnoteSettings
Package: @univerjs-pro/docs-reference · Type definitions
@univerjs-pro/docs-shape
FDocument.getShape
Returns a document Shape by its stable identifier.
getShape(shapeId: string): FShape | FConnectorShape | nullParameters
shapeId— Required.
Returns
The Shape facade, or null when it does not exist.
Examples
const fDocument = univerAPI.getActiveDocument()const fShape = fDocument.getShape('shape-1')console.log(fShape)Types: FShape · FConnectorShape
Package: @univerjs-pro/docs-shape · Type definitions
FDocument.getShapes
Returns all Shapes and Connectors in document drawing order.
getShapes(): Array<FShape | FConnectorShape>Returns
The Shape facades in document drawing order.
Examples
const fDocument = univerAPI.getActiveDocument()const fShapes = fDocument.getShapes()console.log(fShapes)Types: FShape · FConnectorShape · Array
Package: @univerjs-pro/docs-shape · Type definitions
FDocument.insertShape
Inserts a Shape or Connector into this document.
A document Shape is anchored by a persisted paragraph id, so edits before that paragraph do not invalidate
the insertion target. Inline Shapes follow text flow and cannot specify a floating position. The other four
wrapping styles accept placement.position: its horizontal offset is page-relative and its vertical offset
is relative to the anchor paragraph. Prefer square or top-and-bottom wrapping for ordinary floating content.
Front-of-text and behind-text Shapes do not cause text to reflow: use them only for intentional overlays,
backgrounds, or watermarks. transform controls only width, height, and rotation.
insertShape(input: IDocShapeCreateInput): FShape | FConnectorShape | nullParameters
input— Required. Shape data, document placement, size, and rotation.
Returns
A live document Shape facade, or null when creation fails.
Examples
Insert an inline Shape at the end of the first paragraph
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument?.getParagraphs()[0]if (!fDocument || !paragraph) throw new Error('Document paragraph not found.')const fShape = fDocument.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Rect, placement: { wrappingStyle: univerAPI.Enum.TextWrappingStyle.INLINE, anchor: { paragraphId: paragraph.getId(), segmentId: paragraph.getSegmentId(), position: univerAPI.Enum.DocShapeAnchorPosition.PARAGRAPH_END, }, }, transform: { width: 180, height: 72 },})if (!fShape) throw new Error('Shape could not be inserted.')Insert a floating Shape with square text wrapping
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument?.findParagraphByText('Quarterly revenue')if (!fDocument || !paragraph) throw new Error('Anchor paragraph not found.')const fShape = fDocument.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.RoundRect, placement: { wrappingStyle: univerAPI.Enum.TextWrappingStyle.WRAP_SQUARE, anchor: { paragraphId: paragraph.getId(), segmentId: paragraph.getSegmentId(), }, position: { horizontalOffset: 96, verticalOffset: 24 }, }, transform: { width: 240, height: 120, rotation: 5 }, shapeData: { fill: { fillType: univerAPI.Enum.ShapeFillEnum.SolidFill, color: '#dcfce7' }, stroke: { lineStrokeType: univerAPI.Enum.ShapeLineTypeEnum.SolidLine, color: '#16a34a', width: 2, }, },})if (!fShape) throw new Error('Shape could not be inserted.')fShape.getText().setText('Quarterly revenue')Insert a top-and-bottom Formula Shape at a paragraph character offset
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument?.getParagraphs()[0]if (!fDocument || !paragraph) throw new Error('Document paragraph not found.')const fShape = fDocument.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Rect, placement: { wrappingStyle: univerAPI.Enum.TextWrappingStyle.WRAP_TOP_AND_BOTTOM, anchor: { paragraphId: paragraph.getId(), segmentId: paragraph.getSegmentId(), position: univerAPI.Enum.DocShapeAnchorPosition.OFFSET, offset: 0, }, position: { horizontalOffset: 72, verticalOffset: 16 }, }, transform: { width: 280, height: 80 },})if (!fShape) throw new Error('Shape could not be inserted.')fShape.setFormula({ formula: '=SUM([Sales]Data!B2:B10)', externalReferences: [ { qualifier: 'Sales', sourceUnitId: 'sales-workbook', sourceUnitType: univerAPI.Enum.UniverInstanceType.UNIVER_SHEET, }, ],})Insert an intentional foreground overlay that may cover document text
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument?.getParagraphs()[0]if (!fDocument || !paragraph) throw new Error('Document paragraph not found.')const fShape = fDocument.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Ellipse, placement: { // This overlay does not reserve text-layout space and can cover body text. wrappingStyle: univerAPI.Enum.TextWrappingStyle.IN_FRONT_OF_TEXT, anchor: { paragraphId: paragraph.getId(), segmentId: paragraph.getSegmentId(), }, position: { horizontalOffset: 120, verticalOffset: 24 }, }, transform: { width: 180, height: 100 },})if (!fShape) throw new Error('Shape could not be inserted.')fShape.getText().setText('Foreground note')Insert a background Shape behind document text
const fDocument = univerAPI.getActiveDocument()const paragraph = fDocument?.getParagraphs()[0]if (!fDocument || !paragraph) throw new Error('Document paragraph not found.')const fShape = fDocument.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Rect, placement: { // Text does not reflow, so use a low-contrast fill that preserves readability. wrappingStyle: univerAPI.Enum.TextWrappingStyle.BEHIND_TEXT, anchor: { paragraphId: paragraph.getId(), segmentId: paragraph.getSegmentId(), }, position: { horizontalOffset: 72, verticalOffset: 12 }, }, transform: { width: 320, height: 120 }, shapeData: { fill: { fillType: univerAPI.Enum.ShapeFillEnum.SolidFill, color: '#dbeafe' }, },})if (!fShape) throw new Error('Shape could not be inserted.')fShape.setSelectable(false)Types: FShape · FConnectorShape · IDocShapeCreateInput
Package: @univerjs-pro/docs-shape · Type definitions
@univerjs-pro/docs-table
FDocument.findTableByText
Finds the first table whose data stream contains the given text in this document body or header/footer body by the segment id.
findTableByText(text: string, segmentId?: string): FDocumentTable | nullParameters
text— Required. Text to search inside table cells.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The first FDocumentTable instance matching the query, or null if no matches are found.
Examples
const fDocument = univerAPI.getActiveDocument()const table = fDocument.findTableByText('Revenue')console.log(table)const headerSegmentId = fDocument.ensurePageHeader()const headerTable = fDocument.findTableByText('Revenue', headerSegmentId)console.log(headerTable)Types: FDocumentTable
Package: @univerjs-pro/docs-table · Type definitions
FDocument.findTables
Finds tables by text, id, header text, or title text in this document body or header/footer body by the segment id.
findTables(query: string | IDocsTableFindQuery, segmentId?: string): FDocumentTable[]Parameters
query— Required. A plain text query or a structured table query.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
An array of FDocumentTable instances matching the query, or an empty array if no matches are found.
Examples
const fDocument = univerAPI.getActiveDocument()const tablesWithText = fDocument.findTables('Revenue')console.log(tablesWithText)const tablesWithId = fDocument.findTables({ tableId: 'table-1' })console.log(tablesWithId)const tablesWithHeader = fDocument.findTables({ headerText: 'Q1' })console.log(tablesWithHeader)const tablesWithTitle = fDocument.findTables({ titleText: 'Sales Data' })console.log(tablesWithTitle)const footerSegmentId = fDocument.ensurePageFooter()const footerTablesWithText = fDocument.findTables('Revenue', footerSegmentId)console.log(footerTablesWithText)Types: FDocumentTable · IDocsTableFindQuery
Package: @univerjs-pro/docs-table · Type definitions
FDocument.getTable
Returns a table by table id in this document body or header/footer body by the segment id.
getTable(tableId: string, segmentId?: string): FDocumentTable | nullParameters
tableId— Required. The table id stored in the document snapshot.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The FDocumentTable instance, or null if no table with the given id exists in the document.
Examples
const fDocument = univerAPI.getActiveDocument()const table = fDocument.getTable('table-1')console.log(table)const headerSegmentId = fDocument.ensurePageHeader()const headerTable = fDocument.getTable('table-1', headerSegmentId)console.log(headerTable)Types: FDocumentTable
Package: @univerjs-pro/docs-table · Type definitions
FDocument.getTableAt
Returns a table by its order in this document body or header/footer body by the segment id.
getTableAt(index: number, segmentId?: string): FDocumentTable | nullParameters
index— Required. The zero-based table index.segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
The FDocumentTable instance, or null if the index is out of bounds.
Examples
const fDocument = univerAPI.getActiveDocument()const firstTable = fDocument.getTableAt(0)console.log(firstTable)const footerSegmentId = fDocument.ensurePageFooter()const firstFooterTable = fDocument.getTableAt(0, footerSegmentId)console.log(firstFooterTable)Types: FDocumentTable
Package: @univerjs-pro/docs-table · Type definitions
FDocument.getTableAtSelection
Returns the table currently selected by the docs table selection service.
getTableAtSelection(): FDocumentTable | nullReturns
The FDocumentTable instance, or null if there is no current table selection.
Examples
const fDocument = univerAPI.getActiveDocument()const selectedTable = fDocument.getTableAtSelection()console.log(selectedTable)console.log(selectedTable?.getSegmentId())Types: FDocumentTable
Package: @univerjs-pro/docs-table · Type definitions
FDocument.getTables
Returns all enhanced docs tables in this document body or header/footer body by the segment id.
getTables(segmentId?: string): FDocumentTable[]Parameters
segmentId— Optional. Default:''. The segment id of the body. Defaults to an empty string for the main body.
Returns
An array of FDocumentTable instances, or an empty array if the document contains no tables.
Examples
const fDocument = univerAPI.getActiveDocument()const tables = fDocument.getTables()console.log(tables)const headerSegmentId = fDocument.ensurePageHeader()const headerTables = fDocument.getTables(headerSegmentId)console.log(headerTables)Types: FDocumentTable
Package: @univerjs-pro/docs-table · Type definitions
FDocument.insertTable
Inserts an empty table at the current document selection or at the position provided in options.
insertTable(rows: number, columns: number, options?: IDocsTableInsertOptions): FDocumentTable | nullParameters
rows— Required. The row count.columns— Required. The column count.options— Optional. Default:{}. Optional table id, position, metadata, and layout options.
Returns
The inserted FDocumentTable instance, or null if the insert table failed.
Examples
const fDocument = univerAPI.getActiveDocument()// Insert a 3x4 table at the default position (document end)const table = fDocument.insertTable(3, 4)// Insert a 3x4 table at the current selectionconst table2 = fDocument.insertTable(3, 4, { position: univerAPI.Enum.DocsTableInsertTablePosition.Selection,})// Insert a 3x4 table with cell values at a specific offsetconst table3 = fDocument.insertTable(3, 4, { position: univerAPI.Enum.DocsTableInsertTablePosition.Offset, offset: 1000, values: [ ['A1', 'B1', 'C1', 'D1'], ['A2', 'B2', 'C2', 'D2'], ['A3', 'B3', 'C3', 'D3'], ],})// Insert a 2x2 table into the page headerconst headerSegmentId = fDocument.ensurePageHeader()const headerTable = fDocument.insertTable(2, 2, { segmentId: headerSegmentId,})Types: FDocumentTable · IDocsTableInsertOptions
Package: @univerjs-pro/docs-table · Type definitions
FDocument.insertTableFromData
Inserts a table and fills it with plain text cell data.
insertTableFromData(data: string[][], options?: IDocsTableInsertOptions): FDocumentTable | nullParameters
data— Required. Two-dimensional cell text data.options— Optional. Default:{}. Optional table id, position, metadata, and layout options.
Returns
The inserted FDocumentTable instance, or null if the insert table failed.
Examples
const fDocument = univerAPI.getActiveDocument()// Insert a table with 2 rows and 3 columns, and fill it with dataconst table = fDocument.insertTableFromData( [ ['Name', 'Status', 'Version'], ['Facade', 'Ready', '0.26.0'], ], { headerRowCount: 1, },)// Insert a table with data into the page footerconst footerSegmentId = fDocument.ensurePageFooter()const footerTable = fDocument.insertTableFromData( [ ['Reviewed by', 'Date'], ['Docs Team', '2026-07-03'], ], { segmentId: footerSegmentId, },)Types: FDocumentTable · IDocsTableInsertOptions
Package: @univerjs-pro/docs-table · Type definitions
How is this guide?