# Document Data Structure

- Human documentation: [https://docs.univer.ai/guides/docs/model/document-data](https://docs.univer.ai/guides/docs/model/document-data)

- Agent Markdown: [https://docs.univer.ai/guides/docs/model/document-data.md](https://docs.univer.ai/guides/docs/model/document-data.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [docs/model/document-data.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/docs/model/document-data.mdx)

---

## IDocumentData

[`IDocumentData`](https://reference.univer.ai/en-US/interfaces/IDocumentData) is the snapshot format used by Univer Docs.

It describes a complete document unit, including the text body, document-level style, 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.                                                              |
| body?          | `IDocumentBody`     | Main rich-text body. [Details](https://docs.univer.ai/guides/docs/model/document-body.md)             |
| 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 for:

1. [Creating a Univer Docs document](https://docs.univer.ai/guides/docs/features/core/docs-api.md#create-document)
2. [Saving a Univer Docs snapshot](https://docs.univer.ai/guides/docs/features/core/docs-api.md#get-document-data)
3. [Importing or exporting `.docx` files](https://docs.univer.ai/guides/docs/features/import-export.md)
4. Storing rich text inside Sheets cells through `ICellData.p`

> [!WARNING]
> A snapshot is a persisted data structure. Do not mutate it directly after a document is running. Use Facade APIs or commands to modify document content.
