Document Body Structure
IDocumentBody
IDocumentBody stores the main flow content of a Univer Docs document.
The text itself is stored in dataStream. Styles and structure are stored in parallel arrays, and each entry is linked to the text by index.
Properties
| Property | Type | Description |
|---|---|---|
| dataStream | string | The document body as plain text. 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 are stored 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 authoritative source of 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 elements are stored as 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, or block-level features, use Facade APIs or commands instead of writing control characters by hand.
Relationship with IDocumentData
IDocumentBody covers only the main document flow. All other 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?