xlsx/rel-target-mode-external--https

An external hyperlink on a SpreadsheetML worksheet cell must declare TargetMode="External" in xl/worksheets/_rels/sheet1.xml.rels.

Library verdicts: python-xlsx: — xlsxjs: —

Metadata

Feature idxlsx/rel-target-mode-external--https
Formatxlsx
Categoryopc-packaging
Familyxlsx/rel-target-mode-external
Axis valueslink=https
Spececma-376-5-part-2 § 9.3 r:Relationship

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
sheet-hyperlink-rel-exists-https
xl/worksheets/_rels/sheet1.xml.rels
exist
The worksheet's rels part must declare a hyperlink relationship whose Target is the fixture URL.
//r:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink' and @Target='https://example.com/page']
sheet-hyperlink-target-mode-external-https
xl/worksheets/_rels/sheet1.xml.rels
equal = External
TargetMode on the worksheet's external hyperlink rel must be 'External' (OPC §9.3).
//r:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink' and @Target='https://example.com/page']/@TargetMode

Render assertions

No render assertions declared.

Generator source

scripts/gen_xlsx_rel_target_mode_external.py

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

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/rel-target-mode-external--https",
  "kind": "literal",
  "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--https"
  },
  "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"
  },
  "_expansion": {
    "parent_id": "xlsx/rel-target-mode-external",
    "bindings": {
      "link": "https"
    }
  },
  "assertions": [
    {
      "id": "sheet-hyperlink-rel-exists-https",
      "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='https://example.com/page']",
      "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-https",
      "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='https://example.com/page']/@TargetMode",
      "must": "equal",
      "value": "External",
      "description": "TargetMode on the worksheet's external hyperlink rel must be 'External' (OPC §9.3)."
    }
  ]
}

Fixture

Download rel-target-mode-external--https.xlsx (5.1 KB)

Reference preview

No rendered reference is available for this case.

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