An external hyperlink on a SpreadsheetML worksheet cell must declare TargetMode="External" in xl/worksheets/_rels/sheet1.xml.rels.
| Feature ID | Axis bindings | python-xlsx | xlsxjs |
|---|---|---|---|
xlsx/rel-target-mode-external--https | link=https | — | — |
xlsx/rel-target-mode-external--mailto | link=mailto | — | — |
| Library | Pass | Fail | Pending |
|---|---|---|---|
python-xlsx | 0 | 0 | 2 |
xlsxjs | 0 | 0 | 2 |
link (2 values): https, mailtoscripts/gen_xlsx_rel_target_mode_external.py — runs with --arg_template --url "{link.url}" --text "{link.text}" --out fixtures/xlsx/rel-target-mode-external--{link.id}.xlsx
#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/rel-target-mode-external--<id>.xlsx`` fixtures.
A single-sheet workbook whose A1 cell carries an external hyperlink. In
python-xlsx (the openpyxl-derived fork) cell-level hyperlinks are assigned
via ``cell.hyperlink = '<url>'``, which serialises as a Relationship entry
in ``xl/worksheets/_rels/sheet1.xml.rels`` with ``TargetMode="External"``.
Manifest: ``features/xlsx/rel-target-mode-external.json``
"""
from __future__ import annotations
import argparse
from pathlib import Path
from xlsx import Workbook
_REPO_ROOT = Path(__file__).resolve().parent.parent
def _write(url: str, text: str, out: Path) -> None:
wb = Workbook()
ws = wb.active
ws["A1"] = text
ws["A1"].hyperlink = url
out.parent.mkdir(parents=True, exist_ok=True)
wb.save(str(out), zip_date_time=(1980, 1, 1, 0, 0, 0))
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--url", required=True, help="External URI for the cell hyperlink")
parser.add_argument("--text", required=True, help="Display text for the cell")
parser.add_argument("--out", required=True, help="Output fixture path (repo-relative 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.url, args.text, out_path)
print(out_path)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"$schema": "../manifest.schema.json",
"id": "xlsx/rel-target-mode-external",
"kind": "parameterised",
"title": "External relationship target mode (xlsx)",
"format": "xlsx",
"category": "opc-packaging",
"summary": "An external hyperlink on a SpreadsheetML worksheet cell must declare TargetMode=\"External\" in xl/worksheets/_rels/sheet1.xml.rels.",
"spec": {
"source": "ecma-376-5-part-2",
"clause": "9.3",
"element": "r:Relationship",
"notes": "ECMA-376 Part 2 (OPC) §9.3 — an external URI Target on a Relationship MUST carry TargetMode=\"External\". Cell-level hyperlinks in python-xlsx (openpyxl-derived `cell.hyperlink = '<url>'`) serialise an entry in the worksheet's _rels part with that attribute set."
},
"fixtures": {
"machine": "xlsx/rel-target-mode-external"
},
"generator": {
"python": "scripts/gen_xlsx_rel_target_mode_external.py",
"arg_template": "--url \"{link.url}\" --text \"{link.text}\" --out fixtures/xlsx/rel-target-mode-external--{link.id}.xlsx"
},
"parameters": {
"link": [
{
"id": "https",
"url": "https://example.com/page",
"text": "Visit example HTTPS"
},
{
"id": "mailto",
"url": "mailto:contact@example.com",
"text": "Send email"
}
]
},
"assertions_template": [
{
"id": "sheet-hyperlink-rel-exists-{link.id}",
"part": "xl/worksheets/_rels/sheet1.xml.rels",
"namespaces": {
"r": "http://schemas.openxmlformats.org/package/2006/relationships"
},
"xpath": "//r:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink' and @Target='{link.url}']",
"must": "exist",
"description": "The worksheet's rels part must declare a hyperlink relationship whose Target is the fixture URL."
},
{
"id": "sheet-hyperlink-target-mode-external-{link.id}",
"part": "xl/worksheets/_rels/sheet1.xml.rels",
"namespaces": {
"r": "http://schemas.openxmlformats.org/package/2006/relationships"
},
"xpath": "//r:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink' and @Target='{link.url}']/@TargetMode",
"must": "equal",
"value": "External",
"description": "TargetMode on the worksheet's external hyperlink rel must be 'External' (OPC §9.3)."
}
]
}