GuidesUniver SheetsGet StartedConfigure Workbook Data

Univer Sheets Data Structures

This document describes the main data structures used in Univer Sheet: IWorkbookData and IWorksheetData.

IWorkbookData

IWorkbookData represents the snapshot of a workbook in Univer Sheet.

Properties

PropertyTypeDescription
idstringUnique identifier of the Univer Sheets.
namestringName of the Univer Sheets.
appVersionstringVersion of the Univer model definition.
localeLocaleTypeLocale of the document.
stylesRecord<string, Nullable<IStyleData>>Style references for the workbook.
sheetOrderstring[]Array of sheet IDs representing the order of worksheets.
sheets{ [sheetId: string]: Partial<IWorksheetData> }Record containing data for each worksheet.
resources?IResourcesStore the data of plugins

Example

const workbookData: IWorkbookData = {
  id: 'unique-workbook-id',
  name: 'My Workbook',
  appVersion: '1.0.0',
  locale: LocaleType.EN_US,
  styles: { /* style definitions */ },
  sheetOrder: ['sheet1', 'sheet2'],
  sheets: {
    sheet1: { /* sheet data */ },
    sheet2: { /* sheet data */ }
  }
};

Usage

IWorkbookData is the object used to store data in Univer Sheets. It is mainly used for:

  1. Creating a Univer Sheets using IWorkbookData
  2. Saving IWorkbookData from Univer Sheets

resources property is used to store plugin data. Go to Plugin Custom Model

IWorksheetData

IWorksheetData represents the snapshot of a worksheet in Univer Sheet.

Properties

PropertyTypeDescription
idstringUnique identifier for the worksheet.
namestringName of the worksheet.
tabColorstringColor of the worksheet tab.
hiddenBooleanNumberWhether the sheet is hidden. Default: BooleanNumber.FALSE.
freezeIFreezeFreeze pane settings.
rowCountnumberTotal number of rows.
columnCountnumberTotal number of columns.
defaultColumnWidthnumberDefault width for columns.
defaultRowHeightnumberDefault height for rows.
mergeDataIRange[]Array of merged cell ranges.
cellDataIObjectMatrixPrimitiveType<ICellData>Matrix of cell contents. More details.
rowDataIObjectArrayPrimitiveType<Partial<IRowData>>Array of row data objects.
columnDataIObjectArrayPrimitiveType<Partial<IColumnData>>Array of column data objects.
rowHeader{ width: number; hidden?: BooleanNumber; }Row header configuration.
columnHeader{ height: number; hidden?: BooleanNumber; }Column header configuration.
showGridlinesBooleanNumberWhether gridlines are visible.
rightToLeftBooleanNumberWhether the worksheet is in right-to-left mode.
defaultStyle?Nullable<IStyleData>The default style of worksheet

Example

const worksheetData: IWorksheetData = {
  id: 'sheet1',
  name: 'Sheet 1',
  tabColor: '#FF0000',
  hidden: BooleanNumber.FALSE,
  freeze: { xSplit: 1, ySplit: 1, startRow: 1, startColumn: 1 },
  rowCount: 1000,
  columnCount: 26,
  defaultColumnWidth: 100,
  defaultRowHeight: 25,
  mergeData: [],
  cellData: {
    '0': {
      '0': {
        v: 123
      }
    }
  },
  rowData: [],
  columnData: [],
  rowHeader: { width: 40 },
  columnHeader: { height: 20 },
  showGridlines: BooleanNumber.TRUE,
  rightToLeft: BooleanNumber.FALSE
};

This structure provides a comprehensive representation of worksheet data, including layout, content, and display settings.

Full Example

const workbook: IWorkbookData = {
  "id": "gyI0JO",
  "sheetOrder": [
    "RSfWjJFv4opmE1JaiRj80"
  ],
  "name": "",
  "appVersion": "0.5.0",
  "locale": "enUS",
  "styles": {},
  "sheets": {
    "RSfWjJFv4opmE1JaiRj80": {
      "id": "RSfWjJFv4opmE1JaiRj80",
      "name": "Test",
      "tabColor": "",
      "hidden": 0,
      "rowCount": 30,
      "columnCount": 10,
      "zoomRatio": 1,
      "freeze": {
        "startRow": -1,
        "startColumn": -1,
        "ySplit": 0,
        "xSplit": 0
      },
      "scrollTop": 0,
      "scrollLeft": 0,
      "defaultColumnWidth": 73,
      "defaultRowHeight": 23,
      "mergeData": [],
      "cellData": {},
      "rowData": {},
      "columnData": {
        "0": {
          "w": 125,
          "hd": 0
        },
        "1": {
          "w": 125,
          "hd": 0
        },
        "2": {
          "w": 125,
          "hd": 0
        },
        "3": {
          "w": 125,
          "hd": 0
        },
        "4": {
          "w": 125,
          "hd": 0
        },
        "5": {
          "w": 125,
          "hd": 0
        },
        "6": {
          "w": 125,
          "hd": 0
        },
        "7": {
          "w": 125,
          "hd": 0
        },
        "8": {
          "w": 125,
          "hd": 0
        },
        "9": {
          "w": 125,
          "hd": 0
        }
      },
      "showGridlines": 1,
      "rowHeader": {
        "width": 46,
        "hidden": 0
      },
      "columnHeader": {
        "height": 20,
        "hidden": 0
      },
      "selections": [
        "A1"
      ],
      "rightToLeft": 0
    }
  },
  "resources": [
    {
      "name": "SHEET_DEFINED_NAME_PLUGIN",
      "data": ""
    }
  ]
}

Was this page helpful?