xlsx/sheet-view-option--rtl

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: —

Metadata

Feature idxlsx/sheet-view-option--rtl
Formatxlsx
Categorysheet-layout
Familyxlsx/sheet-view-option
Axis valuesoption=rtl
Spececma-376-5-part-1 § 18.3.1.87 sheetView

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
sheet-view-rtl
xl/worksheets/sheet1.xml
match = ^(true|1|0)$
The <sheetView>@rightToLeft attribute must be present and serialise the boolean (true) — XML boolean form '0'/'1' is also accepted.
//x:sheetViews/x:sheetView/@rightToLeft

Render assertions

No render assertions declared.

Generator source

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())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/sheet-view-option--rtl",
  "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--rtl"
  },
  "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": "rtl"
    }
  },
  "assertions": [
    {
      "id": "sheet-view-rtl",
      "part": "xl/worksheets/sheet1.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:sheetViews/x:sheetView/@rightToLeft",
      "must": "match",
      "value": "^(true|1|0)$",
      "description": "The <sheetView>@rightToLeft attribute must be present and serialise the boolean (true) — XML boolean form '0'/'1' is also accepted."
    }
  ]
}

Fixture

Download sheet-view-option--rtl.xlsx (4.7 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/sheet-view-option--rtl page 1 reference

Reference PDF


Download PDF Open in PDF.js

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