xlsx/cell-alignment-horizontal--left

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

Library verdicts: python-xlsx: — xlsxjs: —

Metadata

Feature idxlsx/cell-alignment-horizontal--left
Formatxlsx
Categorycell-formatting
Familyxlsx/cell-alignment-horizontal
Axis valuesalign=left
Spececma-376-5-part-1 § 18.8.1 alignment

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
horizontal-alignment-left
xl/styles.xml
equal = left
A <cellXfs>/<xf>/<alignment>/@horizontal attribute must carry the expected ST_HorizontalAlignment value.
//x:cellXfs/x:xf/x:alignment/@horizontal

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
cell-alignment-horizontal-left-cell-presentcss_selector/ exist
The rendered sheet must contain the aligned cell.
section.xlsx td
sheet-count-leftcss_selector/ equal-count
Exactly one rendered sheet section per case. Catches renderers that emit zero sheets (hard failure).
section.xlsx
cell-alignment-horizontal-left-computed-text-aligncomputed_style = {align.css_re} style=text-align
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.
section.xlsx td, section.xlsx th

Generator source

scripts/gen_cell_alignment_horizontal.py

#!/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 (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/cell-alignment-horizontal--left",
  "kind": "literal",
  "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--left"
  },
  "generator": {
    "python": "scripts/gen_cell_alignment_horizontal.py",
    "arg_template": "--align {align.val} --out fixtures/xlsx/cell-alignment-horizontal--{align.id}.xlsx"
  },
  "_expansion": {
    "parent_id": "xlsx/cell-alignment-horizontal",
    "bindings": {
      "align": "left"
    }
  },
  "assertions": [
    {
      "id": "horizontal-alignment-left",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:cellXfs/x:xf/x:alignment/@horizontal",
      "must": "equal",
      "value": "left",
      "description": "A <cellXfs>/<xf>/<alignment>/@horizontal attribute must carry the expected ST_HorizontalAlignment value."
    }
  ],
  "render_assertions": [
    {
      "id": "cell-alignment-horizontal-left-cell-present",
      "kind": "css_selector",
      "selector": "section.xlsx td",
      "must": "exist",
      "description": "The rendered sheet must contain the aligned cell."
    },
    {
      "id": "sheet-count-left",
      "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-left-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."
    }
  ]
}

Fixture

Download cell-alignment-horizontal--left.xlsx (4.8 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/cell-alignment-horizontal--left page 1 reference

Reference PDF


Download PDF Open in PDF.js

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.