xlsx/cell-wrap-text--shrink-on--wrap-off

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.

Library verdicts: python-xlsx: — xlsxjs: —

Metadata

Feature idxlsx/cell-wrap-text--shrink-on--wrap-off
Formatxlsx
Categorycell-formatting
Familyxlsx/cell-wrap-text
Axis valuesshrink=shrink-on, wrap=wrap-off
Spececma-376-5-part-1 § 18.8.1 alignment

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
wrap-text-wrap-off
xl/styles.xml
absent =
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``).
//x:cellXfs/x:xf/x:alignment/@wrapText
shrink-to-fit-shrink-on
xl/styles.xml
equal = 1
The <alignment>/@shrinkToFit attribute must be ``1`` when shrinkToFit=True and must be absent when shrinkToFit=False.
//x:cellXfs/x:xf/x:alignment/@shrinkToFit

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
cell-wrap-text-shrink-on-wrap-off-cell-presentcss_selector/ exist
The rendered sheet must contain the cell.
section.xlsx td
sheet-count-shrink-oncss_selector/ equal-count
Exactly one rendered sheet section per case. Catches renderers that emit zero sheets (hard failure).
section.xlsx

Generator source

scripts/gen_cell_wrap_text.py

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

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/cell-wrap-text--shrink-on--wrap-off",
  "kind": "literal",
  "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--shrink-on--wrap-off"
  },
  "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"
  },
  "_expansion": {
    "parent_id": "xlsx/cell-wrap-text",
    "bindings": {
      "shrink": "shrink-on",
      "wrap": "wrap-off"
    }
  },
  "assertions": [
    {
      "id": "wrap-text-wrap-off",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:cellXfs/x:xf/x:alignment/@wrapText",
      "must": "absent",
      "value": "",
      "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-on",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:cellXfs/x:xf/x:alignment/@shrinkToFit",
      "must": "equal",
      "value": "1",
      "description": "The <alignment>/@shrinkToFit attribute must be ``1`` when shrinkToFit=True and must be absent when shrinkToFit=False."
    }
  ],
  "render_assertions": [
    {
      "id": "cell-wrap-text-shrink-on-wrap-off-cell-present",
      "kind": "css_selector",
      "selector": "section.xlsx td",
      "must": "exist",
      "description": "The rendered sheet must contain the cell."
    },
    {
      "id": "sheet-count-shrink-on",
      "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)."
    }
  ]
}

Fixture

Download cell-wrap-text--shrink-on--wrap-off.xlsx (4.8 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/cell-wrap-text--shrink-on--wrap-off page 1 reference

Reference PDF


Download PDF Open in PDF.js

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.