w:tblStylePr (Conditional Table Style Formatting)
Defines conditional formatting applied to specific regions of a table (e.g., first row, last column, banded rows) within a table style definition.
Description
w:tblStylePr is a conditional formatting block within a table style (w:style with w:type="table"). It applies different formatting to specific structural regions of the table — such as the header row, first column, or banded rows — without requiring separate style definitions.
It is defined in ECMA-376 Part 1 §17.7.6.1.
The w:type attribute selects which region the formatting applies to, and the child property elements define the look for that region.
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
w:type |
ST_TblStyleOverrideType |
See below | Selects the table region this formatting applies to. |
w:type values
| Value | Region |
|---|---|
wholeTable |
All cells |
firstRow |
Header row |
lastRow |
Total/summary row |
firstCol |
First column |
lastCol |
Last column |
band1Vert |
Odd banded columns |
band2Vert |
Even banded columns |
band1Horz |
Odd banded rows |
band2Horz |
Even banded rows |
neCell |
Top-right corner cell |
nwCell |
Top-left corner cell |
seCell |
Bottom-right corner cell |
swCell |
Bottom-left corner cell |
Examples
<!-- Table style: header row in bold with shaded background -->
<w:style w:type="table" w:styleId="TableGrid">
<w:name w:val="Table Grid"/>
<w:tblStylePr w:type="firstRow">
<w:rPr>
<w:b/>
</w:rPr>
<w:tcPr>
<w:shd w:val="solid" w:color="4472C4" w:fill="4472C4"/>
</w:tcPr>
</w:tblStylePr>
<!-- wholeTable and other regions omitted -->
</w:style>
using DocumentFormat.OpenXml.Wordprocessing;
var style = new Style(
new StyleName { Val = "Table Grid" },
new TableStyleProperties(
new StyleRunProperties(new Bold()),
new TableStyleCellProperties(
new Shading
{
Val = ShadingPatternValues.Solid,
Color = "4472C4",
Fill = "4472C4"
}
)
)
{ Type = TableStyleOverrideValues.FirstRow }
)
{
Type = StyleValues.Table,
StyleId = "TableGrid"
};
Notes
- Multiple
w:tblStylePrchildren may be present, each with a differentw:type. - The
w:tblPrchild within aw:tblStylePrshould not containw:tblStyle(which would create a circular reference). - Table look flags (
w:tblLook) in the actual table control which conditional regions are applied at render time.