xlsx/sheet-view-option

Boolean toggles on <sheetView> — showGridLines, showRowColHeaders, tabSelected, rightToLeft — are emitted as 0/1 attributes when they deviate from their ECMA-376 default.

Cases (4)

Feature IDAxis bindingspython-xlsxxlsxjs
xlsx/sheet-view-option--rtloption=rtl
xlsx/sheet-view-option--show-gridlines-offoption=show-gridlines-off
xlsx/sheet-view-option--show-row-col-headers-offoption=show-row-col-headers-off
xlsx/sheet-view-option--tab-selectedoption=tab-selected

Aggregate

LibraryPassFailPending
python-xlsx004
xlsxjs004

Parameter axes

Spec 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').

Generator source

scripts/gen_sheet_view_option.py — runs with --arg_template --attr {option.attr} --val {option.enabled_val} --out fixtures/xlsx/sheet-view-option--{option.id}.xlsx

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

Manifest (parent, unexpanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/sheet-view-option",
  "kind": "parameterised",
  "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"
  },
  "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"
  },
  "parameters": {
    "option": [
      {
        "id": "show-gridlines-off",
        "attr": "showGridLines",
        "enabled_val": "false",
        "disabled_val": "true"
      },
      {
        "id": "show-row-col-headers-off",
        "attr": "showRowColHeaders",
        "enabled_val": "false",
        "disabled_val": "true"
      },
      {
        "id": "tab-selected",
        "attr": "tabSelected",
        "enabled_val": "true",
        "disabled_val": "false"
      },
      {
        "id": "rtl",
        "attr": "rightToLeft",
        "enabled_val": "true",
        "disabled_val": "false"
      }
    ]
  },
  "assertions_template": [
    {
      "id": "sheet-view-{option.id}",
      "part": "xl/worksheets/sheet1.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:sheetViews/x:sheetView/@{option.attr}",
      "must": "match",
      "value": "^({option.enabled_val}|1|0)$",
      "description": "The <sheetView>@{option.attr} attribute must be present and serialise the boolean ({option.enabled_val}) — XML boolean form '0'/'1' is also accepted."
    }
  ]
}