Boolean toggles on <sheetView> — showGridLines, showRowColHeaders, tabSelected, rightToLeft — are emitted as 0/1 attributes when they deviate from their ECMA-376 default.
Library verdicts: python-xlsx: — xlsxjs: —
| Feature id | xlsx/sheet-view-option--show-row-col-headers-off |
|---|---|
| Format | xlsx |
| Category | sheet-layout |
| Family | xlsx/sheet-view-option |
| Axis values | option=show-row-col-headers-off |
| Spec | ecma-376-5-part-1 § 18.3.1.87 sheetView |
| ID / part | Predicate | XPath | python-xlsx | xlsxjs |
|---|---|---|---|---|
sheet-view-show-row-col-headers-offxl/worksheets/sheet1.xml | match = ^(false|1|0)$The <sheetView>@showRowColHeaders attribute must be present and serialise the boolean (false) — XML boolean form '0'/'1' is also accepted. | //x:sheetViews/x:sheetView/@showRowColHeaders | — | — |
No render assertions declared.
scripts/gen_sheet_view_option.py
#!/usr/bin/env python3
"""Generate a ``fixtures/xlsx/sheet-view-option--<id>.xlsx`` fixture.
Parameterised generator for the ``xlsx/sheet-view-option`` manifest.
Writes a minimal one-sheet workbook and toggles one boolean attribute
on the active sheet's ``<sheetView>`` element — ``showGridLines``,
``showRowColHeaders``, ``tabSelected``, or ``rightToLeft``.
Only deviating-from-default directions are parameterised: the
``show-gridlines-off`` and ``show-row-col-headers-off`` cases flip a
default-true attribute to false; the ``tab-selected`` and ``rtl``
cases flip a default-false attribute to true. Setting a default-valued
attribute explicitly is pruned by python-xlsx's writer and would not
appear in the output XML.
"""
from __future__ import annotations
import argparse
import datetime as _dt
from pathlib import Path
from xlsx import Workbook
_REPO_ROOT = Path(__file__).resolve().parent.parent
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)
# Map manifest --attr value (camelCase OOXML name) to the
# SheetView attribute on python-xlsx. python-xlsx keeps the OOXML
# camelCase spelling verbatim on the SheetView class.
_ATTR_MAP = {
"showGridLines": "showGridLines",
"showRowColHeaders": "showRowColHeaders",
"tabSelected": "tabSelected",
"rightToLeft": "rightToLeft",
}
def _parse_bool(text: str) -> bool:
if text.lower() == "true":
return True
if text.lower() == "false":
return False
raise argparse.ArgumentTypeError(
f"--val expects 'true' or 'false', got {text!r}"
)
def _write(attr: str, value: bool, out: Path) -> None:
if attr not in _ATTR_MAP:
raise ValueError(
f"Unsupported --attr {attr!r}; choose one of "
f"{sorted(_ATTR_MAP)}."
)
wb = Workbook()
ws = wb.active
ws["A1"] = "Sheet view test"
setattr(ws.sheet_view, _ATTR_MAP[attr], value)
out.parent.mkdir(parents=True, exist_ok=True)
wb.save(out, zip_date_time=_REPRODUCIBLE_DT)
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
"--attr",
required=True,
choices=sorted(_ATTR_MAP),
help="OOXML attribute name on <sheetView> to toggle.",
)
parser.add_argument(
"--val",
required=True,
type=_parse_bool,
help="Boolean value to assign ('true' or 'false').",
)
parser.add_argument(
"--out",
required=True,
help="Output fixture path (relative to repo root or absolute).",
)
args = parser.parse_args()
out_path = Path(args.out)
if not out_path.is_absolute():
out_path = _REPO_ROOT / out_path
_write(args.attr, args.val, out_path)
print(out_path)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"$schema": "../manifest.schema.json",
"id": "xlsx/sheet-view-option--show-row-col-headers-off",
"kind": "literal",
"title": "Sheet-view boolean options",
"format": "xlsx",
"category": "sheet-layout",
"summary": "Boolean toggles on <sheetView> — showGridLines, showRowColHeaders, tabSelected, rightToLeft — are emitted as 0/1 attributes when they deviate from their ECMA-376 default.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "18.3.1.87",
"element": "sheetView",
"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.3.1.87 defines <sheetView> and its boolean attributes. Defaults per spec: showGridLines=true, showRowColHeaders=true, tabSelected=false, rightToLeft=false. A compliant writer MAY (and python-xlsx does) omit an attribute when it matches the default — so this family only exercises the deviating direction for each attribute: show-gridlines-off and show-row-col-headers-off flip a default-true to false, while tab-selected and rtl flip a default-false to true. The 'on' direction for the default-true attributes is unobservable in the XML (python-xlsx's prune_defaults strips them) and is therefore not covered by this family. Boolean attributes in SpreadsheetML may serialise as '0'/'1' (xsd:boolean canonical form) or 'true'/'false' — the regex anchors accept both. SpreadsheetML parts use a default namespace with no prefix; XPath needs an explicit binding (here 'x')."
},
"fixtures": {
"machine": "xlsx/sheet-view-option--show-row-col-headers-off"
},
"generator": {
"python": "scripts/gen_sheet_view_option.py",
"arg_template": "--attr {option.attr} --val {option.enabled_val} --out fixtures/xlsx/sheet-view-option--{option.id}.xlsx"
},
"_expansion": {
"parent_id": "xlsx/sheet-view-option",
"bindings": {
"option": "show-row-col-headers-off"
}
},
"assertions": [
{
"id": "sheet-view-show-row-col-headers-off",
"part": "xl/worksheets/sheet1.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:sheetViews/x:sheetView/@showRowColHeaders",
"must": "match",
"value": "^(false|1|0)$",
"description": "The <sheetView>@showRowColHeaders attribute must be present and serialise the boolean (false) — XML boolean form '0'/'1' is also accepted."
}
]
}
