PPTX

表格

创建带合并单元格、自定义样式和格式化内容的表格

使用 table 向幻灯片添加结构化的表格数据。

基本表格

{
  "slides": [
    {
      "children": [
        {
          "table": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "21.2cm",
            "height": "7.9cm",
            "rows": [
              { "cells": [{ "text": "Name" }, { "text": "Role" }, { "text": "Department" }] },
              { "cells": [{ "text": "Alice" }, { "text": "Engineer" }, { "text": "Dev" }] },
              { "cells": [{ "text": "Bob" }, { "text": "Designer" }, { "text": "UX" }] }
            ]
          }
        }
      ]
    }
  ]
}

单元格格式

使用 children 配合段落对象实现格式化的单元格内容:

{
  "slides": [
    {
      "children": [
        {
          "table": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "21.2cm",
            "height": "7.9cm",
            "rows": [
              {
                "cells": [
                  {
                    "fill": "2E74B5",
                    "verticalAlign": "center",
                    "children": [
                      {
                        "children": [
                          { "text": "Header", "bold": true, "size": 14, "fill": "FFFFFF" }
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                "cells": [
                  {
                    "fill": "F2F2F2",
                    "children": [
                      {
                        "children": [{ "text": "Data cell", "size": 12 }]
                      }
                    ]
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  ]
}

丰富的单元格内容

单元格可以包含多个段落:

{
    cells: [
        {
            children: [
                {
                    children: [
                        { text: "Bold title", bold: true, size: 14 },
                    ],
                },
                {
                    children: [
                        { text: "Description", size: 11, fill: "666666" },
                    ],
                },
            ],
        },
    ],
}

合并单元格

使用 rowSpancolumnSpan 合并单元格:

{
  "slides": [
    {
      "children": [
        {
          "table": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "21.2cm",
            "height": "9.3cm",
            "rows": [
              {
                "cells": [{ "text": "Category", "rowSpan": 2 }, { "text": "Q1" }, { "text": "Q2" }]
              },
              {
                "cells": [{ "text": "100" }, { "text": "120" }]
              },
              {
                "cells": [
                  { "text": "Products", "rowSpan": 2 },
                  { "text": "200" },
                  { "text": "250" }
                ]
              },
              { "cells": [{ "text": "210" }, { "text": "270" }] }
            ]
          }
        }
      ]
    }
  ]
}

列宽

显式控制列宽:

{
  "slides": [
    {
      "children": [
        {
          "table": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "21.2cm",
            "columnWidths": [200, 300, 300],
            "rows": [
              { "cells": [{ "text": "ID" }, { "text": "Name" }, { "text": "Email" }] },
              { "cells": [{ "text": "1" }, { "text": "Alice" }, { "text": "alice@example.com" }] }
            ]
          }
        }
      ]
    }
  ]
}

边框

自定义单元格边框:

{
    text: "Cell with border",
    borders: {
        top: { width: 2, color: "2E74B5" },
        bottom: { width: 2, color: "2E74B5" },
        left: { width: 2, color: "2E74B5" },
        right: { width: 2, color: "2E74B5" },
    },
}

表格级边框会分配到边缘单元格:

{
  "slides": [
    {
      "children": [
        {
          "table": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "21.2cm",
            "rows": [
              { "cells": [{ "text": "A" }, { "text": "B" }] },
              { "cells": [{ "text": "C" }, { "text": "D" }] }
            ],
            "borders": {
              "top": { "width": 2, "color": "2E74B5" },
              "bottom": { "width": 2, "color": "2E74B5" },
              "left": { "width": 2, "color": "2E74B5" },
              "right": { "width": 2, "color": "2E74B5" }
            }
          }
        }
      ]
    }
  ]
}

Table 选项

属性类型说明
xnumber | UniversalMeasure水平位置
ynumber | UniversalMeasure垂直位置
widthnumber | UniversalMeasure框架宽度
heightnumber | UniversalMeasure框架高度
rowsTableRowOptions[]表格行
columnWidthsnumber[]每列宽度
bordersobject表格级边缘边框
firstRowboolean首行加粗样式
bandRowboolean交替行条纹

单元格选项

属性类型说明
textstring纯文本内容
children(ParagraphDescriptorOptions | string)[]段落对象
fillFillOptions单元格背景填充
bordersobject单元格边框
columnSpannumber水平合并数
rowSpannumber垂直合并数
verticalAlign"top" | "center" | "bottom" | "justify" | "distribute"垂直文本对齐
vert"horz" | "vert" | "vert270" | "wordArt" | "wordArtV"单元格内文本方向(a:tcPr @vert)
margins{ top, bottom, left, right }单元格内边距

边框选项

属性类型说明
widthnumber | UniversalMeasure边框宽度
colorstring十六进制颜色
dash"solid" | "dash" | "dashDot" | "lgDash" | ...虚线样式
Copyright © 2026