# 工作表資料結構

- Human documentation: [https://docs.univer.ai/zh-TW/guides/sheets/model/worksheet-data](https://docs.univer.ai/zh-TW/guides/sheets/model/worksheet-data)

- Agent Markdown: [https://docs.univer.ai/zh-TW/guides/sheets/model/worksheet-data.md](https://docs.univer.ai/zh-TW/guides/sheets/model/worksheet-data.md)

- Requested language: `zh-TW`

- Content language: `zh-TW`

- Documentation version: `1.2.0`

- Source: [sheets/model/worksheet-data.zh-TW.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/sheets/model/worksheet-data.zh-TW.mdx)

---

## IWorksheetData

[`IWorksheetData`](https://docs.univer.ai/zh-TW/reference/types/worksheet-data.md) 表示 Univer Sheets 中工作表的快照。

### 屬性

| 屬性                                                          | 類型                                                | 描述                                                                                                                             |
| ----------------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| id                                                          | `string`                                          | 工作表的唯一識別碼。                                                                                                                     |
| name                                                        | `string`                                          | 工作表的名稱。                                                                                                                        |
| tabColor                                                    | `string`                                          | 工作表標籤的顏色。                                                                                                                      |
| hidden                                                      | `BooleanNumber`                                   | 工作表是否隱藏。預設值：`BooleanNumber.FALSE`。                                                                                             |
| freeze                                                      | `IFreeze`                                         | 凍結窗格設定。                                                                                                                        |
| rowCount                                                    | `number`                                          | 總列數。                                                                                                                           |
| columnCount                                                 | `number`                                          | 總欄數。                                                                                                                           |
| defaultColumnWidth                                          | `number`                                          | 欄的預設寬度，單位 `px`。                                                                                                                |
| defaultRowHeight                                            | `number`                                          | 列的預設高度，單位 `px`。                                                                                                                |
| mergeData                                                   | `IRange[]`                                        | 合併儲存格範圍的陣列。                                                                                                                    |
| cellData                                                    | `IObjectMatrixPrimitiveType<ICellData>`           | 儲存格內容的矩陣。[詳情](https://docs.univer.ai/zh-TW/guides/sheets/model/cell-data.md)                                                                                  |
| rowData                                                     | `IObjectArrayPrimitiveType<Partial<IRowData>>`    | 列資料物件的陣列。                                                                                                                      |
| columnData                                                  | `IObjectArrayPrimitiveType<Partial<IColumnData>>` | 欄資料物件的陣列。                                                                                                                      |
| rowHeader                                                   | `{ width: number; hidden?: BooleanNumber; }`      | 列標題設定。                                                                                                                         |
| columnHeader                                                | `{ height: number; hidden?: BooleanNumber; }`     | 欄標題設定。                                                                                                                         |
| backgroundImage?                                            | `IWorksheetBackgroundImage`                       | 選用的平鋪圖片來源：`{ source: string; imageSourceType: ImageSourceType }`。參閱[背景圖](https://docs.univer.ai/zh-TW/guides/sheets/features/images.md#worksheet-background)。 |
| showGridlines                                               | `BooleanNumber`                                   | 是否顯示格線。                                                                                                                        |
| rightToLeft                                                 | `BooleanNumber`                                   | 工作表是否為由右至左模式。                                                                                                                  |
| [defaultStyle](https://docs.univer.ai/zh-TW/guides/sheets/features/core/default-style.md)? | `Nullable<IStyleData>`                            | 預設工作表樣式                                                                                                                        |

### 範例

```typescript
const worksheetData: IWorksheetData = {
  id: 'sheet1',
  name: '工作表 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,
}
```

此結構提供了工作表資料的完整呈現，包含版面配置、內容與顯示設定。

## 完整範例

```typescript
const workbook: IWorkbookData = {
  id: 'gyI0JO',
  sheetOrder: [
    'RSfWjJFv4opmE1JaiRj80',
  ],
  name: '',
  appVersion: '0.10.2',
  locale: 'zhCN',
  styles: {},
  sheets: {
    RSfWjJFv4opmE1JaiRj80: {
      id: 'RSfWjJFv4opmE1JaiRj80',
      name: '測試',
      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,
      },
      rightToLeft: 0,
    },
  },
  resources: [
    {
      name: 'SHEET_DEFINED_NAME_PLUGIN',
      data: '',
    },
  ],
}
```
