xlsx/cell-alignment-vertical

Apply each of four ST_VerticalAlignment values to cell A1; the value appears in xl/styles.xml as <cellXfs>/<xf>/<alignment>/@vertical.

Cases (4)

Feature IDAxis bindingspython-xlsxxlsxjs
xlsx/cell-alignment-vertical--bottomalign=bottom
xlsx/cell-alignment-vertical--centeralign=center
xlsx/cell-alignment-vertical--justifyalign=justify
xlsx/cell-alignment-vertical--topalign=top

Aggregate

LibraryPassFailPending
python-xlsx004
xlsxjs004

Parameter axes

Spec notes

ECMA-376 Part 1 clause 18.18.88 defines ST_VerticalAlignment with five values: top, center, bottom, justify, distributed. SpreadsheetML carries the setting on a <alignment vertical="<val>"/> child of an <xf> record in <cellXfs> (clause 18.8.1). This manifest covers four of the five values — top/center/bottom/justify — the canonical Excel dropdown picks; ``distributed`` is exercised separately. All four values round-trip through python-xlsx verbatim. SpreadsheetML parts use a default namespace with no prefix; XPath needs an explicit binding (here 'x'). One manifest file expands into 4 concrete fixture cases.

Generator source

scripts/gen_cell_alignment_vertical.py — runs with --arg_template --align {align.val} --out fixtures/xlsx/cell-alignment-vertical--{align.id}.xlsx

#!/usr/bin/env python3
"""Generate a ``fixtures/xlsx/cell-alignment-vertical--<id>.xlsx`` fixture.

Parameterised generator for the ``xlsx/cell-alignment-vertical``
manifest. Writes a minimal one-sheet workbook with cell A1 carrying a
text value and ``Alignment(vertical=<val>)`` applied to it.
python-xlsx emits the setting as
``<alignment vertical=\"<val>\"/>`` on the corresponding
``<cellXfs>/<xf>`` entry in xl/styles.xml.
"""

from __future__ import annotations

import argparse
import datetime as _dt
from pathlib import Path

from xlsx import Workbook
from xlsx.styles import Alignment

_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)
_REPO_ROOT = Path(__file__).resolve().parent.parent


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--align", required=True, help="ST_VerticalAlignment value")
    parser.add_argument("--out", required=True, help="Output fixture path")
    args = parser.parse_args()

    out_path = Path(args.out)
    if not out_path.is_absolute():
        out_path = _REPO_ROOT / out_path

    wb = Workbook()
    ws = wb.active
    ws["A1"] = f"v={args.align}"
    ws["A1"].alignment = Alignment(vertical=args.align)
    out_path.parent.mkdir(parents=True, exist_ok=True)
    wb.save(out_path, zip_date_time=_REPRODUCIBLE_DT)
    print(out_path)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Manifest (parent, unexpanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/cell-alignment-vertical",
  "kind": "parameterised",
  "title": "Cell vertical alignment (4 ST_VerticalAlignment values)",
  "format": "xlsx",
  "category": "cell-formatting",
  "summary": "Apply each of four ST_VerticalAlignment values to cell A1; the value appears in xl/styles.xml as <cellXfs>/<xf>/<alignment>/@vertical.",
  "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": "ECMA-376 Part 1 clause 18.18.88 defines ST_VerticalAlignment with five values: top, center, bottom, justify, distributed. SpreadsheetML carries the setting on a <alignment vertical=\"<val>\"/> child of an <xf> record in <cellXfs> (clause 18.8.1). This manifest covers four of the five values — top/center/bottom/justify — the canonical Excel dropdown picks; ``distributed`` is exercised separately. All four values round-trip through python-xlsx verbatim. SpreadsheetML parts use a default namespace with no prefix; XPath needs an explicit binding (here 'x'). One manifest file expands into 4 concrete fixture cases."
  },
  "fixtures": {
    "machine": "xlsx/cell-alignment-vertical"
  },
  "generator": {
    "python": "scripts/gen_cell_alignment_vertical.py",
    "arg_template": "--align {align.val} --out fixtures/xlsx/cell-alignment-vertical--{align.id}.xlsx"
  },
  "parameters": {
    "align": [
      {
        "id": "top",
        "val": "top"
      },
      {
        "id": "center",
        "val": "center"
      },
      {
        "id": "bottom",
        "val": "bottom"
      },
      {
        "id": "justify",
        "val": "justify"
      }
    ]
  },
  "assertions_template": [
    {
      "id": "vertical-alignment-{align.id}",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:cellXfs/x:xf/x:alignment/@vertical",
      "must": "equal",
      "value": "{align.val}",
      "description": "A <cellXfs>/<xf>/<alignment>/@vertical attribute must carry the expected ST_VerticalAlignment value."
    }
  ],
  "render_assertions_template": [
    {
      "id": "cell-alignment-vertical-{align.id}-cell-present",
      "kind": "css_selector",
      "selector": "section.xlsx td",
      "must": "exist",
      "description": "The rendered sheet must contain the aligned cell."
    },
    {
      "id": "sheet-count-{align.id}",
      "kind": "css_selector",
      "selector": "section.xlsx",
      "must": "equal-count",
      "count": 1,
      "description": "Exactly one rendered sheet section per case. Catches renderers that emit zero sheets (hard failure)."
    },
    {
      "id": "cell-alignment-vertical-{align.id}-computed-vertical-align",
      "kind": "computed_style",
      "selector": "section.xlsx td, section.xlsx th",
      "style_property": "vertical-align",
      "value": "{align.css_re}",
      "description": "Accessibility/semantics: the computed vertical-align on the rendered table cell should reflect the authored ST_VerticalAlignment. 'top'/'bottom' map to the same CSS names; ST_VerticalAlignment 'center' maps to CSS 'middle' (either literal is accepted); 'justify' has no canonical CSS parallel and accepts anything."
    }
  ]
}