xlsx/cell-wrap-text

Apply every combination of wrapText and shrinkToFit (True/False) to cell A1; each flag appears in xl/styles.xml as an @wrapText / @shrinkToFit attribute on <cellXfs>/<xf>/<alignment>, or is elided when False.

Cases (4)

Feature IDAxis bindingspython-xlsxxlsxjs
xlsx/cell-wrap-text--shrink-off--wrap-offshrink=shrink-off, wrap=wrap-off
xlsx/cell-wrap-text--shrink-off--wrap-onshrink=shrink-off, wrap=wrap-on
xlsx/cell-wrap-text--shrink-on--wrap-offshrink=shrink-on, wrap=wrap-off
xlsx/cell-wrap-text--shrink-on--wrap-onshrink=shrink-on, wrap=wrap-on

Aggregate

LibraryPassFailPending
python-xlsx004
xlsxjs004

Parameter axes

Spec notes

ECMA-376 Part 1 clause 18.8.1 (CT_CellAlignment) defines @wrapText and @shrinkToFit as xsd:boolean attributes on <alignment>. SpreadsheetML serialises True as ``1`` (not the literal ``true``). python-xlsx omits the attribute entirely when the Python value is False, rather than emitting ``0`` — both shapes are spec-legal (xsd:boolean default is effectively False when the attribute is absent on these properties). The manifest therefore asserts attribute presence-and-value (``1``) for True cases and attribute absence for False cases. When BOTH axes are False python-xlsx still emits a bare ``<alignment/>`` element (with applyAlignment="1" on the parent <xf>), so the assertion xpaths still have a node to evaluate against. SpreadsheetML parts use a default namespace with no prefix; XPath needs an explicit binding (here 'x'). Axes: wrap (on/off) x shrink (on/off) = 4 cases.

Generator source

scripts/gen_cell_wrap_text.py — runs with --arg_template --wrap {wrap.pybool} --shrink {shrink.pybool} --out fixtures/xlsx/cell-wrap-text--{shrink.id}--{wrap.id}.xlsx

#!/usr/bin/env python3
"""Generate a ``fixtures/xlsx/cell-wrap-text--<wrap>--<shrink>.xlsx`` fixture.

Parameterised generator for the ``xlsx/cell-wrap-text`` manifest.
Writes a minimal one-sheet workbook with cell A1 carrying a text value
and ``Alignment(wrapText=<bool>, shrinkToFit=<bool>)`` applied to it.
python-xlsx emits each True flag as ``@wrapText=\"1\"`` /
``@shrinkToFit=\"1\"`` on the ``<alignment>`` child of a
``<cellXfs>/<xf>`` entry in xl/styles.xml; False flags are elided
(the attribute is omitted entirely, not emitted as ``\"0\"``). The
bare ``<alignment/>`` element is still present even when both axes
are False.
"""

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 _parse_bool(raw: str) -> bool:
    low = raw.strip().lower()
    if low in ("true", "1", "yes", "on"):
        return True
    if low in ("false", "0", "no", "off"):
        return False
    raise argparse.ArgumentTypeError(f"Not a boolean: {raw!r}")


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--wrap", type=_parse_bool, required=True)
    parser.add_argument("--shrink", type=_parse_bool, required=True)
    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"wrap={args.wrap} shrink={args.shrink}"
    ws["A1"].alignment = Alignment(
        wrapText=args.wrap, shrinkToFit=args.shrink
    )
    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-wrap-text",
  "kind": "parameterised",
  "title": "Cell wrap-text and shrink-to-fit (2x2 boolean matrix)",
  "format": "xlsx",
  "category": "cell-formatting",
  "summary": "Apply every combination of wrapText and shrinkToFit (True/False) to cell A1; each flag appears in xl/styles.xml as an @wrapText / @shrinkToFit attribute on <cellXfs>/<xf>/<alignment>, or is elided when False.",
  "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.8.1 (CT_CellAlignment) defines @wrapText and @shrinkToFit as xsd:boolean attributes on <alignment>. SpreadsheetML serialises True as ``1`` (not the literal ``true``). python-xlsx omits the attribute entirely when the Python value is False, rather than emitting ``0`` — both shapes are spec-legal (xsd:boolean default is effectively False when the attribute is absent on these properties). The manifest therefore asserts attribute presence-and-value (``1``) for True cases and attribute absence for False cases. When BOTH axes are False python-xlsx still emits a bare ``<alignment/>`` element (with applyAlignment=\"1\" on the parent <xf>), so the assertion xpaths still have a node to evaluate against. SpreadsheetML parts use a default namespace with no prefix; XPath needs an explicit binding (here 'x'). Axes: wrap (on/off) x shrink (on/off) = 4 cases."
  },
  "fixtures": {
    "machine": "xlsx/cell-wrap-text"
  },
  "generator": {
    "python": "scripts/gen_cell_wrap_text.py",
    "arg_template": "--wrap {wrap.pybool} --shrink {shrink.pybool} --out fixtures/xlsx/cell-wrap-text--{shrink.id}--{wrap.id}.xlsx"
  },
  "parameters": {
    "wrap": [
      {
        "id": "wrap-on",
        "pybool": "True",
        "must": "equal",
        "val": "1"
      },
      {
        "id": "wrap-off",
        "pybool": "False",
        "must": "absent",
        "val": ""
      }
    ],
    "shrink": [
      {
        "id": "shrink-on",
        "pybool": "True",
        "must": "equal",
        "val": "1"
      },
      {
        "id": "shrink-off",
        "pybool": "False",
        "must": "absent",
        "val": ""
      }
    ]
  },
  "assertions_template": [
    {
      "id": "wrap-text-{wrap.id}",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:cellXfs/x:xf/x:alignment/@wrapText",
      "must": "{wrap.must}",
      "value": "{wrap.val}",
      "description": "The <alignment>/@wrapText attribute must be ``1`` when wrapText=True and must be absent when wrapText=False (python-xlsx elides False flags rather than emitting ``0``)."
    },
    {
      "id": "shrink-to-fit-{shrink.id}",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:cellXfs/x:xf/x:alignment/@shrinkToFit",
      "must": "{shrink.must}",
      "value": "{shrink.val}",
      "description": "The <alignment>/@shrinkToFit attribute must be ``1`` when shrinkToFit=True and must be absent when shrinkToFit=False."
    }
  ],
  "render_assertions_template": [
    {
      "id": "cell-wrap-text-{shrink.id}-{wrap.id}-cell-present",
      "kind": "css_selector",
      "selector": "section.xlsx td",
      "must": "exist",
      "description": "The rendered sheet must contain the cell."
    },
    {
      "id": "sheet-count-{shrink.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)."
    }
  ]
}