Document Body Structure
IDocumentBody
IDocumentBody stores the main flow content of a Univer Docs document.
The actual text is stored in dataStream. Styles and structural information are stored in parallel arrays and linked to the text through indexes.
Properties
| Property | Type | Description |
|---|---|---|
| dataStream | string | Plain text stream of the document body. Special characters mark paragraphs, section breaks, tables, and custom blocks. |
| textRuns? | ITextRun[] | Inline style ranges. |
| paragraphs? | IParagraph[] | Paragraph metadata and paragraph styles. |
| sectionBreaks? | ISectionBreak[] | Section break metadata. |
| customBlocks? | ICustomBlock[] | Plugin-defined block placeholders. |
| tables? | ICustomTable[] | Table markers in the document body. Table definitions live in IDocumentData.tableSource. |
| columnGroups? | ICustomColumnGroup[] | Column group markers. |
| blockRanges? | IDocumentBlockRange[] | Structured block ranges such as callout, quote, and code blocks. |
| customRanges? | ICustomRange[] | Special ranges such as hyperlinks, fields, bookmarks, comments, mentions, and plugin-defined ranges. |
| customDecorations? | ICustomDecoration[] | Decoration ranges such as comment highlights. |
| payloads? | Record<string, string> | Temporary copy/paste payloads. This field is not persisted. |
dataStream
dataStream is the source of truth for the body text. A paragraph usually ends with \r\n.
TypeScript
const body: IDocumentBody = { dataStream: 'Title\r\nHello Univer\r\n', paragraphs: [ { startIndex: 5, paragraphId: 'p-title' }, { startIndex: 19, paragraphId: 'p-body' }, ],}Special Characters
Some document elements are represented by control characters in dataStream and expanded by the renderer:
| Character | Meaning |
|---|---|
\r\n | Paragraph break |
\n | Section break |
\f | Page break |
\v | Column break |
\t | Tab |
\0 | Document end |
\b | Custom block placeholder |
Tables and custom ranges also use control characters internally. When working with tables, links, comments, and block-level features, prefer Facade APIs or commands instead of hand-writing control characters.
Relationship with IDocumentData
IDocumentBody only stores the main document flow. External resources are stored on IDocumentData:
tableSourcestores table definitions.drawingsstores image and drawing objects.headersandfooterseach contain their ownIDocumentBody.listsstores list definitions referenced by paragraph bullets.resourcesstores plugin-defined data.
How is this guide?