A workbook defines a cellXfs entry with an <alignment> child declaring horizontal and vertical centering and applies it to cell A1.
Library verdicts: python-xlsx: — xlsxjs: pass
| Feature id | xlsx/cell-alignment |
|---|---|
| Format | xlsx |
| Category | cell-formatting |
| Spec | ecma-376-5-part-1 § 18.8.1 alignment |
| ID / part | Predicate | XPath | python-xlsx | xlsxjs |
|---|---|---|---|---|
cellxf-horizontal-centerxl/styles.xml | existAt least one <xf> in <cellXfs> must declare an <alignment> child with horizontal='center'. | //x:cellXfs/x:xf[x:alignment/@horizontal='center'] | — | — |
cellxf-vertical-centerxl/styles.xml | existAt least one <xf> in <cellXfs> must declare an <alignment> child with vertical='center'. | //x:cellXfs/x:xf[x:alignment/@vertical='center'] | — | — |
shared-string-presentxl/sharedStrings.xml | existThe shared-strings table must contain 'Centered cell'. | //x:sst/x:si/x:t[normalize-space()='Centered cell'] | — | — |
| ID | Predicate | Selector | python-xlsx | xlsxjs |
|---|---|---|---|---|
cell-alignment-text-present | css_selector/ match-text = Centered cellThe rendered sheet must contain a cell with the fixture text. | section.xlsx td, section.xlsx th | — | pass |
cell-alignment-is-centered | computed_style = ^center$ style=text-alignThe computed text-align on the cell must be 'center'. | section.xlsx td, section.xlsx th | — | pass |
sheet-count | css_selector/ equal-countExactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet. | section.xlsx | — | — |
scripts/gen_cell_alignment.py
#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/cell-alignment.xlsx``.
A minimal one-sheet workbook with cell A1 containing ``Centered cell``
formatted with horizontal and vertical center alignment. Designed to
satisfy the assertions in ``features/xlsx/cell-alignment.json``.
"""
from __future__ import annotations
from pathlib import Path
from xlsx import Workbook
from xlsx.styles import Alignment
import datetime as _dt
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "xlsx" / "cell-alignment.xlsx"
def main() -> int:
wb = Workbook()
ws = wb.active
ws["A1"] = "Centered cell"
ws["A1"].alignment = Alignment(horizontal="center", vertical="center")
_OUT.parent.mkdir(parents=True, exist_ok=True)
wb.save(_OUT, zip_date_time=_REPRODUCIBLE_DT)
print(_OUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"$schema": "../manifest.schema.json",
"id": "xlsx/cell-alignment",
"title": "Cell alignment (horizontal + vertical center)",
"format": "xlsx",
"category": "cell-formatting",
"summary": "A workbook defines a cellXfs entry with an <alignment> child declaring horizontal and vertical centering and applies it to cell A1.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "18.8.1",
"element": "alignment",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
"notes": "Alignment in SpreadsheetML lives on a <xf> entry in xl/styles.xml's <cellXfs> table as an <alignment horizontal=\"...\" vertical=\"...\"/> child. A cell with t=\"s\" and a matching s=\"...\" xfId then inherits that alignment. The assertion here checks the simpler shape: at least one <xf> in <cellXfs> has an <alignment> child with horizontal='center' and (separately) vertical='center'. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x'). Content of cell A1 appears in xl/sharedStrings.xml as an <si><t>Centered cell</t></si> entry."
},
"fixtures": {
"machine": "xlsx/cell-alignment",
"office": "xlsx/cell-alignment"
},
"generator": {
"python": "scripts/gen_cell_alignment.py"
},
"assertions": [
{
"id": "cellxf-horizontal-center",
"part": "xl/styles.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:cellXfs/x:xf[x:alignment/@horizontal='center']",
"must": "exist",
"description": "At least one <xf> in <cellXfs> must declare an <alignment> child with horizontal='center'."
},
{
"id": "cellxf-vertical-center",
"part": "xl/styles.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:cellXfs/x:xf[x:alignment/@vertical='center']",
"must": "exist",
"description": "At least one <xf> in <cellXfs> must declare an <alignment> child with vertical='center'."
},
{
"id": "shared-string-present",
"part": "xl/sharedStrings.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:sst/x:si/x:t[normalize-space()='Centered cell']",
"must": "exist",
"description": "The shared-strings table must contain 'Centered cell'."
}
],
"render_assertions": [
{
"id": "cell-alignment-text-present",
"kind": "css_selector",
"selector": "section.xlsx td, section.xlsx th",
"must": "match-text",
"value": "Centered cell",
"description": "The rendered sheet must contain a cell with the fixture text."
},
{
"id": "cell-alignment-is-centered",
"kind": "computed_style",
"selector": "section.xlsx td, section.xlsx th",
"style_property": "text-align",
"value": "^center$",
"description": "The computed text-align on the cell must be 'center'."
},
{
"id": "sheet-count",
"kind": "css_selector",
"selector": "section.xlsx",
"must": "equal-count",
"count": 1,
"description": "Exactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet."
}
]
}
