xlsx/cell-alignment-horizontal

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

Cases (6)

Feature IDAxis bindingspython-xlsxxlsxjs
xlsx/cell-alignment-horizontal--centeralign=center
xlsx/cell-alignment-horizontal--fillalign=fill
xlsx/cell-alignment-horizontal--generalalign=general
xlsx/cell-alignment-horizontal--justifyalign=justify
xlsx/cell-alignment-horizontal--leftalign=left
xlsx/cell-alignment-horizontal--rightalign=right

Aggregate

LibraryPassFailPending
python-xlsx006
xlsxjs006

Parameter axes

Spec notes

ECMA-376 Part 1 clause 18.18.40 defines ST_HorizontalAlignment with eight values: general, left, center, right, fill, justify, centerContinuous, distributed. SpreadsheetML carries the setting on a <alignment horizontal="<val>"/> child of an <xf> record in <cellXfs> (clause 18.8.1). This manifest covers six of the eight values — general/left/center/right/fill/justify — chosen because they are the canonical Excel alignment dropdown picks; the remaining two (centerContinuous, distributed) are left for dedicated exercises. All six 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 6 concrete fixture cases.

Generator source

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

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

Parameterised generator for the ``xlsx/cell-alignment-horizontal``
manifest. Writes a minimal one-sheet workbook with cell A1 carrying a
text value and ``Alignment(horizontal=<val>)`` applied to it.
python-xlsx emits the setting as
``<alignment horizontal=\"<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_HorizontalAlignment 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"h={args.align}"
    ws["A1"].alignment = Alignment(horizontal=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-horizontal",
  "kind": "parameterised",
  "title": "Cell horizontal alignment (6 ST_HorizontalAlignment values)",
  "format": "xlsx",
  "category": "cell-formatting",
  "summary": "Apply each of six ST_HorizontalAlignment values to cell A1; the value appears in xl/styles.xml as <cellXfs>/<xf>/<alignment>/@horizontal.",
  "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.40 defines ST_HorizontalAlignment with eight values: general, left, center, right, fill, justify, centerContinuous, distributed. SpreadsheetML carries the setting on a <alignment horizontal=\"<val>\"/> child of an <xf> record in <cellXfs> (clause 18.8.1). This manifest covers six of the eight values — general/left/center/right/fill/justify — chosen because they are the canonical Excel alignment dropdown picks; the remaining two (centerContinuous, distributed) are left for dedicated exercises. All six 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 6 concrete fixture cases."
  },
  "fixtures": {
    "machine": "xlsx/cell-alignment-horizontal"
  },
  "generator": {
    "python": "scripts/gen_cell_alignment_horizontal.py",
    "arg_template": "--align {align.val} --out fixtures/xlsx/cell-alignment-horizontal--{align.id}.xlsx"
  },
  "parameters": {
    "align": [
      {
        "id": "general",
        "val": "general"
      },
      {
        "id": "left",
        "val": "left"
      },
      {
        "id": "center",
        "val": "center"
      },
      {
        "id": "right",
        "val": "right"
      },
      {
        "id": "fill",
        "val": "fill"
      },
      {
        "id": "justify",
        "val": "justify"
      }
    ]
  },
  "assertions_template": [
    {
      "id": "horizontal-alignment-{align.id}",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:cellXfs/x:xf/x:alignment/@horizontal",
      "must": "equal",
      "value": "{align.val}",
      "description": "A <cellXfs>/<xf>/<alignment>/@horizontal attribute must carry the expected ST_HorizontalAlignment value."
    }
  ],
  "render_assertions_template": [
    {
      "id": "cell-alignment-horizontal-{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-horizontal-{align.id}-computed-text-align",
      "kind": "computed_style",
      "selector": "section.xlsx td, section.xlsx th",
      "style_property": "text-align",
      "value": "{align.css_re}",
      "description": "Accessibility/semantics: the computed text-align on the rendered cell should reflect the authored ST_HorizontalAlignment. 'left'/'center'/'right'/'justify' map to the same CSS names (with 'left' also accepting 'start' and 'right' accepting 'end' per CSS logical properties). 'general' and 'fill' have no canonical CSS parallel and accept anything; the check still requires the selector to hit."
    }
  ]
}