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: —
| Feature id | xlsx/cell-wrap-text--shrink-on--wrap-on |
|---|---|
| Format | xlsx |
| Category | cell-formatting |
| Family | xlsx/cell-wrap-text |
| Axis values | shrink=shrink-on, wrap=wrap-on |
| Spec | ecma-376-5-part-1 § 18.8.1 alignment |
| ID / part | Predicate | XPath | python-xlsx | xlsxjs |
|---|---|---|---|---|
wrap-text-wrap-onxl/styles.xml | equal = 1The <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-onxl/styles.xml | equal = 1The <alignment>/@shrinkToFit attribute must be ``1`` when shrinkToFit=True and must be absent when shrinkToFit=False. | //x:cellXfs/x:xf/x:alignment/@shrinkToFit | — | — |
| ID | Predicate | Selector | python-xlsx | xlsxjs |
|---|---|---|---|---|
cell-wrap-text-shrink-on-wrap-on-cell-present | css_selector/ existThe rendered sheet must contain the cell. | section.xlsx td | — | — |
sheet-count-shrink-on | css_selector/ equal-countExactly one rendered sheet section per case. Catches renderers that emit zero sheets (hard failure). | section.xlsx | — | — |
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())
{
"$schema": "../manifest.schema.json",
"id": "xlsx/cell-wrap-text--shrink-on--wrap-on",
"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-on"
},
"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-on"
}
},
"assertions": [
{
"id": "wrap-text-wrap-on",
"part": "xl/styles.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:cellXfs/x:xf/x:alignment/@wrapText",
"must": "equal",
"value": "1",
"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-on-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)."
}
]
}
