A 2x2 table with explicit single-line borders on every edge (top/left/bottom/right/insideH/insideV).
Library verdicts: python-docx: — docxjs: pass
| Feature id | docx/table-borders |
|---|---|
| Format | docx |
| Category | tables |
| Spec | ecma-376-5-part-1 § 17.4.38 w:tblBorders |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
tbl-borders-top-singleword/document.xml | existThe table must declare a single-line top border inside <w:tblPr>/<w:tblBorders>. | //w:tblPr/w:tblBorders/w:top[@w:val='single'] | — | — |
tbl-borders-bottom-singleword/document.xml | existThe table must declare a single-line bottom border. | //w:tblPr/w:tblBorders/w:bottom[@w:val='single'] | — | — |
tbl-borders-left-singleword/document.xml | existThe table must declare a single-line left border. | //w:tblPr/w:tblBorders/w:left[@w:val='single'] | — | — |
tbl-borders-right-singleword/document.xml | existThe table must declare a single-line right border. | //w:tblPr/w:tblBorders/w:right[@w:val='single'] | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
table-border-rendered | css_selector/ existA rendered <table> element must be present under .docx-wrapper. | .docx-wrapper table | — | pass |
table-border-text-smoke | css_selector/ match-text = A1Smoke check: the rendered table cells must include 'A1'. | .docx-wrapper table td, .docx-wrapper table th | — | pass |
table-border-cell-b2-rendered | css_selector/ match-text = ^B2$Row 2 column 2 must be exactly 'B2'. Catches content leaks across cells in a bordered table. | .docx-wrapper table tr:nth-of-type(2) td:nth-of-type(2), .docx-wrapper table tr:nth-of-type(2) th:nth-of-type(2) | — | — |
table-border-has-four-cells | css_selector/ equal-countExactly four rendered cells must exist. Catches accidental cell merging or duplication. | .docx-wrapper table td, .docx-wrapper table th | — | — |
scripts/gen_table_borders.py
#!/usr/bin/env python3
"""Generate ``fixtures/docx/table-borders.docx``.
A 2x2 table with explicit single-line borders on every edge
(top, left, bottom, right, insideH, insideV). Satisfies the assertions
in ``features/docx/table-borders.json``.
Uses the fork's ``Table.set_borders`` high-level API (added in
python-docx 2026.05.0).
"""
from __future__ import annotations
from pathlib import Path
from docx import Document
from docx.enum.table import WD_BORDER_STYLE
from docx.shared import Pt, RGBColor
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "docx" / "table-borders.docx"
def main() -> int:
doc = Document()
table = doc.add_table(rows=2, cols=2)
# Fork high-level API: enable every edge with a single-line style.
table.set_borders(
top=True,
bottom=True,
left=True,
right=True,
inside_h=True,
inside_v=True,
style=WD_BORDER_STYLE.SINGLE,
width=Pt(1),
color=RGBColor(0, 0, 0),
)
table.rows[0].cells[0].text = "A1"
table.rows[0].cells[1].text = "A2"
table.rows[1].cells[0].text = "B1"
table.rows[1].cells[1].text = "B2"
_OUT.parent.mkdir(parents=True, exist_ok=True)
doc.save(_OUT, reproducible=True)
print(_OUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"$schema": "../manifest.schema.json",
"id": "docx/table-borders",
"title": "Table with explicit borders (tblBorders)",
"format": "docx",
"category": "tables",
"summary": "A 2x2 table with explicit single-line borders on every edge (top/left/bottom/right/insideH/insideV).",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "17.4.38",
"element": "w:tblBorders",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
"notes": "<w:tblBorders> inside <w:tblPr> declares the table-level border edges (top, left, bottom, right, insideH, insideV). Each child edge specifies w:val (style, e.g. 'single'), w:sz (eighths-of-a-point), w:space and w:color."
},
"fixtures": {
"machine": "docx/table-borders",
"office": "docx/table-borders"
},
"generator": {
"python": "scripts/gen_table_borders.py"
},
"assertions": [
{
"id": "tbl-borders-top-single",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:tblPr/w:tblBorders/w:top[@w:val='single']",
"must": "exist",
"description": "The table must declare a single-line top border inside <w:tblPr>/<w:tblBorders>."
},
{
"id": "tbl-borders-bottom-single",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:tblPr/w:tblBorders/w:bottom[@w:val='single']",
"must": "exist",
"description": "The table must declare a single-line bottom border."
},
{
"id": "tbl-borders-left-single",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:tblPr/w:tblBorders/w:left[@w:val='single']",
"must": "exist",
"description": "The table must declare a single-line left border."
},
{
"id": "tbl-borders-right-single",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:tblPr/w:tblBorders/w:right[@w:val='single']",
"must": "exist",
"description": "The table must declare a single-line right border."
}
],
"render_assertions": [
{
"id": "table-border-rendered",
"kind": "css_selector",
"selector": ".docx-wrapper table",
"must": "exist",
"description": "A rendered <table> element must be present under .docx-wrapper."
},
{
"id": "table-border-text-smoke",
"kind": "css_selector",
"selector": ".docx-wrapper table td, .docx-wrapper table th",
"must": "match-text",
"value": "A1",
"description": "Smoke check: the rendered table cells must include 'A1'."
},
{
"id": "table-border-cell-b2-rendered",
"kind": "css_selector",
"selector": ".docx-wrapper table tr:nth-of-type(2) td:nth-of-type(2), .docx-wrapper table tr:nth-of-type(2) th:nth-of-type(2)",
"must": "match-text",
"value": "^B2$",
"description": "Row 2 column 2 must be exactly 'B2'. Catches content leaks across cells in a bordered table."
},
{
"id": "table-border-has-four-cells",
"kind": "css_selector",
"selector": ".docx-wrapper table td, .docx-wrapper table th",
"must": "equal-count",
"count": 4,
"description": "Exactly four rendered cells must exist. Catches accidental cell merging or duplication."
}
]
}
