Skip to content
Office Open

DOCX

Tables

Create tables with rows, cells, merged cells, borders, and styling

Use the table, cells, and children properties to add structured data to your documents.

#Basic Table

JSON
{
  "sections": [
    {
      "children": [
        {
          "table": {
            "rows": [
              {
                "cells": [
                  { "children": [{ "paragraph": { "children": [{ "text": "Name" }] } }] },
                  { "children": [{ "paragraph": { "children": [{ "text": "Age" }] } }] }
                ]
              },
              {
                "cells": [
                  { "children": [{ "paragraph": { "children": [{ "text": "Alice" }] } }] },
                  { "children": [{ "paragraph": { "children": [{ "text": "30" }] } }] }
                ]
              }
            ]
          }
        }
      ]
    }
  ]
}

#Column Widths

JSON
{
  "sections": [
    {
      "children": [
        {
          "table": {
            "columnWidths": [3000, 2000, 2000],
            "rows": [
              {
                "cells": [
                  {
                    "children": [{ "paragraph": { "children": ["Col 1"] } }],
                    "width": { "size": 3000, "type": "twips" }
                  },
                  {
                    "children": [{ "paragraph": { "children": ["Col 2"] } }],
                    "width": { "size": 2000, "type": "twips" }
                  },
                  {
                    "children": [{ "paragraph": { "children": ["Col 3"] } }],
                    "width": { "size": 2000, "type": "twips" }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  ]
}

#Merged Cells

Use verticalMerge to merge cells vertically and columnSpan to merge horizontally:

JSON
{
  "sections": [
    {
      "children": [
        {
          "table": {
            "rows": [
              {
                "cells": [
                  {
                    "verticalMerge": "restart",
                    "children": [{ "paragraph": { "children": ["Merged (2 rows)"] } }]
                  },
                  { "children": [{ "paragraph": { "children": ["B1"] } }] }
                ]
              },
              {
                "cells": [
                  {
                    "verticalMerge": "continue",
                    "children": [{ "paragraph": { "children": [] } }]
                  },
                  { "children": [{ "paragraph": { "children": ["B2"] } }] }
                ]
              }
            ]
          }
        }
      ]
    }
  ]
}

#Table Borders

JSON
{
  "sections": [
    {
      "children": [
        {
          "table": {
            "borders": {
              "top": { "style": "single", "size": 1, "color": "000000" },
              "bottom": { "style": "single", "size": 1, "color": "000000" },
              "left": { "style": "single", "size": 1, "color": "000000" },
              "right": { "style": "single", "size": 1, "color": "000000" },
              "insideHorizontal": { "style": "single", "size": 1, "color": "000000" },
              "insideVertical": { "style": "single", "size": 1, "color": "000000" }
            },
            "rows": [
              {
                "cells": [
                  { "children": [{ "paragraph": { "children": ["A"] } }] },
                  { "children": [{ "paragraph": { "children": ["B"] } }] }
                ]
              },
              {
                "cells": [
                  { "children": [{ "paragraph": { "children": ["C"] } }] },
                  { "children": [{ "paragraph": { "children": ["D"] } }] }
                ]
              }
            ]
          }
        }
      ]
    }
  ]
}

#Cell Formatting

Style individual cells with backgrounds, borders, and vertical alignment:

JSON
{
  "sections": [
    {
      "children": [
        {
          "table": {
            "rows": [
              {
                "cells": [
                  {
                    "shading": { "fill": "F2F2F2" },
                    "verticalAlign": "center",
                    "borders": {
                      "top": { "style": "single", "size": 1, "color": "CCCCCC" },
                      "bottom": { "style": "single", "size": 1, "color": "CCCCCC" },
                      "left": { "style": "single", "size": 1, "color": "CCCCCC" },
                      "right": { "style": "single", "size": 1, "color": "CCCCCC" }
                    },
                    "children": [{ "paragraph": { "children": ["Styled cell"] } }]
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  ]
}

#Table Width Modes

Control how the table occupies the page width:

JSON
{
  "sections": [
    {
      "children": [
        {
          "table": {
            "width": { "size": 100, "type": "percent" },
            "rows": [
              {
                "cells": [{ "children": [{ "paragraph": { "children": ["Full width table"] } }] }]
              }
            ]
          }
        }
      ]
    }
  ]
}

Width types:

  • "twips" — Fixed width in twips
  • "percent" — Percentage of page width (100 = 100%)
  • "auto" — Auto-fit to content

#Table Options Reference

OptionTypeDescription
rowsTableRowOptions[]Table rows
widthobjectTable width ({ size, type })
columnWidthsnumber[]Width for each column in TWIPs
bordersobjectBorder definitions for all edges
floatobjectFloating table positioning