Tables
Complete guide to OOXML tables - structure, properties, and implementation gotchas.
Tables in OOXML are built from rows (w:tr) and cells (w:tc). The spec dedicates 200+ pages to tables, but most implementations only need a subset.
Structure
w:tbl (table)
├── w:tblPr (table properties)
│ ├── w:tblW (table width)
│ └── w:tblBorders (borders)
├── w:tblGrid (column grid)
│ └── w:gridCol (column definition)
└── w:tr (table row)
└── w:tc (table cell)
├── w:tcPr (cell properties)
└── w:p (content)
Example
<w:tbl>
<w:tblPr>
<w:tblW w:w="5000" w:type="dxa"/>
<w:tblBorders>
<w:top w:val="single" w:sz="4" w:color="000000"/>
<w:left w:val="single" w:sz="4" w:color="000000"/>
<w:bottom w:val="single" w:sz="4" w:color="000000"/>
<w:right w:val="single" w:sz="4" w:color="000000"/>
<w:insideH w:val="single" w:sz="4" w:color="000000"/>
<w:insideV w:val="single" w:sz="4" w:color="000000"/>
</w:tblBorders>
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="2500"/>
<w:gridCol w:w="2500"/>
</w:tblGrid>
<w:tr>
<w:tc>
<w:p><w:r><w:t>Cell 1</w:t></w:r></w:p>
</w:tc>
<w:tc>
<w:p><w:r><w:t>Cell 2</w:t></w:r></w:p>
</w:tc>
</w:tr>
</w:tbl>
Implementation Notes
tblGrid is required (Word)
The spec marks w:tblGrid as optional. Word crashes without it. Always include it.
Width calculation varies (Word, LibreOffice)
When w:gridCol elements have explicit widths, w:tblW may be ignored. The actual table width becomes the sum of column widths.
Nested tables
Tables can be nested inside w:tc elements. Each nested table is a complete w:tbl element with its own grid.
Schema
| Element | Type | Description |
|---|---|---|
w:tblPr | optional | Table properties (width, alignment, borders) |
w:tblGrid | required* | Column grid definition |
w:tr | 1+ | Table rows |