w:tblGrid (Table Grid)
Defines the column structure of the table by specifying the width of each column slot.
Description
w:tblGrid defines the logical column structure of a table by specifying the width of each column in the table’s grid model. It is defined in ECMA-376 Part 1 §17.4.49.
Each w:gridCol child element represents one column slot with its preferred width in twips (1/20th of a point). The table grid serves as the coordinate system: cell spanning via w:gridSpan and vertical merging via w:vMerge are both specified relative to this grid. The sum of all w:gridCol widths should ideally equal the table’s total width, though Word may adjust rendering based on available space.
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
| (none) | — | — | All column definitions are carried by w:gridCol child elements. |
Examples
<!-- Three equal-width columns (1.5 inch each) -->
<w:tblGrid>
<w:gridCol w:w="2160"/>
<w:gridCol w:w="2160"/>
<w:gridCol w:w="2160"/>
</w:tblGrid>
new TableGrid(
new GridColumn { Width = "2160" },
new GridColumn { Width = "2160" },
new GridColumn { Width = "2160" });
<!-- Four columns with varying widths (1.5", 1", 1", 0.5") -->
<w:tblGrid>
<w:gridCol w:w="2160"/>
<w:gridCol w:w="1440"/>
<w:gridCol w:w="1440"/>
<w:gridCol w:w="720"/>
</w:tblGrid>
new TableGrid(
new GridColumn { Width = "2160" }, // 1.5 inches
new GridColumn { Width = "1440" }, // 1 inch
new GridColumn { Width = "1440" }, // 1 inch
new GridColumn { Width = "720" }); // 0.5 inches
Notes
- Twip Conversion: 1440 twips = 1 inch = 25.4 mm. Divide widths by 1440 to convert to inches.
- Grid Coordinates: The number of
w:gridColelements defines the logical column count. Every row must reference this grid. - Cell Spanning: A cell with
w:gridSpan w:val="2"occupies 2 grid columns. Row gridSpan sum must equal total grid columns. - Column Immutability: Changing the grid structure requires updating all affected rows.
- Width Calculation: Sum all
w:gridColwidths to get logical table width. - AutoFit Mode: If
w:tblLayoutisautofit, rendered widths may differ from grid widths based on content. - Vertical Merge: Grid defines columns;
w:vMerge(row merging) uses same grid coordinates. - Structural Consistency: Every row’s total
w:gridSpanmust equal the grid column count. - Round-Trip Stability: Preserve original grid widths when reading/writing to maintain layout.
- Compatibility: Table grid structure is stable across Office versions.