The workbook part carries a workbook-scoped <definedName> 'MyRange' whose body is the A1-style reference 'Sheet!$A$1:$B$10'.
Library verdicts: python-xlsx: — xlsxjs: —
| Feature id | xlsx/defined-name |
|---|---|
| Format | xlsx |
| Category | workbook |
| Spec | ecma-376-5-part-1 § 18.2.5 definedName |
| ID / part | Predicate | XPath | python-xlsx | xlsxjs |
|---|---|---|---|---|
defined-name-presentxl/workbook.xml | existThe workbook part must carry a <definedName name='MyRange'/> child of <definedNames>. | //x:definedNames/x:definedName[@name='MyRange'] | — | — |
defined-name-valuexl/workbook.xml | equal = Sheet!$A$1:$B$10The MyRange defined name's body must be the A1-style reference 'Sheet!$A$1:$B$10'. | //x:definedNames/x:definedName[@name='MyRange'] | — | — |
No render assertions declared.
scripts/gen_defined_name.py
#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/defined-name.xlsx``.
A minimal one-sheet workbook carrying a workbook-scoped defined name
``MyRange`` that points at ``Sheet!$A$1:$B$10``. The feature under test
is the ``<definedName>`` entry in ``xl/workbook.xml``.
Designed to satisfy the assertions in ``features/xlsx/defined-name.json``.
"""
from __future__ import annotations
import datetime as _dt
from pathlib import Path
from xlsx import Workbook
from xlsx.workbook.defined_name import DefinedName
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "xlsx" / "defined-name.xlsx"
def main() -> int:
wb = Workbook()
ws = wb.active
ws.title = "Sheet"
# Seed the workbook with a couple of values so the name has something
# real to resolve against; not strictly required for the assertion.
ws["A1"] = 1
ws["B10"] = 2
defn = DefinedName(name="MyRange", attr_text="Sheet!$A$1:$B$10")
wb.defined_names.append(defn)
_OUT.parent.mkdir(parents=True, exist_ok=True)
wb.save(_OUT, zip_date_time=_REPRODUCIBLE_DT)
print(_OUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"$schema": "../manifest.schema.json",
"id": "xlsx/defined-name",
"title": "Workbook-scoped defined name",
"format": "xlsx",
"category": "workbook",
"summary": "The workbook part carries a workbook-scoped <definedName> 'MyRange' whose body is the A1-style reference 'Sheet!$A$1:$B$10'.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "18.2.5",
"element": "definedName",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
"notes": "SpreadsheetML defines named ranges via <definedName> children of <definedNames> on the workbook root. A workbook-scoped name omits the localSheetId attribute; a sheet-scoped name would carry it. SpreadsheetML parts use a default namespace with no prefix, so the XPath binds the 'x' prefix explicitly."
},
"fixtures": {
"machine": "xlsx/defined-name",
"office": "xlsx/defined-name"
},
"generator": {
"python": "scripts/gen_defined_name.py"
},
"assertions": [
{
"id": "defined-name-present",
"part": "xl/workbook.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:definedNames/x:definedName[@name='MyRange']",
"must": "exist",
"description": "The workbook part must carry a <definedName name='MyRange'/> child of <definedNames>."
},
{
"id": "defined-name-value",
"part": "xl/workbook.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:definedNames/x:definedName[@name='MyRange']",
"must": "equal",
"value": "Sheet!$A$1:$B$10",
"description": "The MyRange defined name's body must be the A1-style reference 'Sheet!$A$1:$B$10'."
}
]
}
