Document Data Structure
IDocumentData
IDocumentData is the snapshot format for Univer Docs.
A snapshot describes one whole document unit: text body, document-level styles, headers and footers, drawings, lists, tables, and plugin resources.
Properties
| Property | Type | Description |
|---|---|---|
| id | string | Unique document unit ID. |
| rev? | number | Document revision, used by collaborative editing. |
| locale? | LocaleType | Locale of the document. |
| title? | string | Document title. |
| company? | string | Organization associated with the document, used by built-in property fields. |
| customProperties? | Record<string, IDocumentCustomProperty> | Editable document metadata referenced by property fields. Each value is a string, date, integer, number, or boolean. |
| body? | IDocumentBody | Main rich-text body. Details |
| documentStyle | IDocumentStyle | Document-level page, layout, header/footer, and default text style settings. |
| settings? | IDocumentSettings | Runtime settings such as zoomRatio. |
| resources? | IResources | Plugin resources. |
| disabled? | boolean | Whether the document is disabled. |
| headers? | IHeaders | Header bodies keyed by header ID. |
| footers? | IFooters | Footer bodies keyed by footer ID. |
| lists? | ILists | List definitions used by paragraph bullets. |
| drawings? | IDrawings | Drawing objects such as images. |
| drawingsOrder? | string[] | Rendering order of drawings. |
| tableSource? | ITables | Table definitions referenced by the document body. |
Example
TypeScript
const documentData: IDocumentData = { id: 'doc-1', title: 'Demo Document', locale: LocaleType.EN_US, body: { dataStream: 'Hello Univer\r\n', textRuns: [ { st: 0, ed: 12, ts: { fs: 14 }, }, ], paragraphs: [ { startIndex: 12, paragraphId: 'paragraph-1', }, ], }, documentStyle: { pageSize: { width: 595, height: 842 }, marginTop: 72, marginBottom: 72, marginLeft: 72, marginRight: 72, },}Usage
IDocumentData is mainly used in four places:
- Creating a Univer Docs document
- Saving a Univer Docs snapshot
- Importing or exporting
.docxfiles - Storing rich text inside Sheets cells through
ICellData.p
A snapshot is persisted data. Do not mutate it directly while a document is running; use Facade APIs or commands to change document content.
How is this guide?