xlsx/cell-underline

A workbook defines an underlined font in its styles part and carries a shared string for the underlined cell.

Library verdicts: python-xlsx: — xlsxjs: pass

Metadata

Feature idxlsx/cell-underline
Formatxlsx
Categorycell-formatting
Spececma-376-5-part-1 § 18.8.22 font

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
underline-font-defined
xl/styles.xml
exist
At least one <font> entry in the styles part must declare underline via a <u> child.
//x:fonts/x:font[x:u]
shared-string-present
xl/sharedStrings.xml
exist
The shared-strings table must contain 'Hello underline cell'.
//x:sst/x:si/x:t[normalize-space()='Hello underline cell']

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
cell-underline-text-presentcss_selector/ match-text = Hello underline cell
The rendered sheet must contain a cell with the fixture text.
section.xlsx td, section.xlsx thpass
cell-underline-is-underlinecomputed_style = ^underline$ style=text-decoration-line
The computed text-decoration-line on the cell must be underline. (Assumes the renderer applies styles directly — adjust selector if nested in a span.)
section.xlsx td, section.xlsx thpass
sheet-countcss_selector/ equal-count
Exactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet.
section.xlsx

Generator source

scripts/gen_cell_underline.py

#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/cell-underline.xlsx``.

A minimal one-sheet workbook with cell A1 containing ``Hello underline cell``
formatted with a single-underline font. Designed to satisfy the assertions in
``features/xlsx/cell-underline.json``.
"""

from __future__ import annotations

from pathlib import Path

from xlsx import Workbook
from xlsx.styles import Font

import datetime as _dt
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)

_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "xlsx" / "cell-underline.xlsx"


def main() -> int:
    wb = Workbook()
    ws = wb.active
    ws["A1"] = "Hello underline cell"
    ws["A1"].font = Font(underline="single")
    _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())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/cell-underline",
  "title": "Underline cell font",
  "format": "xlsx",
  "category": "cell-formatting",
  "summary": "A workbook defines an underlined font in its styles part and carries a shared string for the underlined cell.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "18.8.22",
    "element": "font",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
    "notes": "Underline in SpreadsheetML lives on a <font> entry in xl/styles.xml's <fonts> table as a <u/> child (python-xlsx emits <u val=\"single\"/>; the presence of the <u> element is the canonical signal and the val attribute selects single / double / singleAccounting / doubleAccounting). A <xf> record in <cellXfs> then points at that fontId. The assertion here checks the simpler shape: at least one <font> in xl/styles.xml contains a <u> child. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x'). Content of cell A1 appears in xl/sharedStrings.xml as an <si><t>Hello underline cell</t></si> entry."
  },
  "fixtures": {
    "machine": "xlsx/cell-underline",
    "office": "xlsx/cell-underline"
  },
  "generator": {
    "python": "scripts/gen_cell_underline.py"
  },
  "assertions": [
    {
      "id": "underline-font-defined",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:fonts/x:font[x:u]",
      "must": "exist",
      "description": "At least one <font> entry in the styles part must declare underline via a <u> child."
    },
    {
      "id": "shared-string-present",
      "part": "xl/sharedStrings.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:sst/x:si/x:t[normalize-space()='Hello underline cell']",
      "must": "exist",
      "description": "The shared-strings table must contain 'Hello underline cell'."
    }
  ],
  "render_assertions": [
    {
      "id": "cell-underline-text-present",
      "kind": "css_selector",
      "selector": "section.xlsx td, section.xlsx th",
      "must": "match-text",
      "value": "Hello underline cell",
      "description": "The rendered sheet must contain a cell with the fixture text."
    },
    {
      "id": "cell-underline-is-underline",
      "kind": "computed_style",
      "selector": "section.xlsx td, section.xlsx th",
      "style_property": "text-decoration-line",
      "value": "^underline$",
      "description": "The computed text-decoration-line on the cell must be underline. (Assumes the renderer applies styles directly — adjust selector if nested in a span.)"
    },
    {
      "id": "sheet-count",
      "kind": "css_selector",
      "selector": "section.xlsx",
      "must": "equal-count",
      "count": 1,
      "description": "Exactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet."
    }
  ]
}

Fixture

Download cell-underline.xlsx (4.7 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/cell-underline page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Underline in SpreadsheetML lives on a <font> entry in xl/styles.xml's <fonts> table as a <u/> child (python-xlsx emits <u val="single"/>; the presence of the <u> element is the canonical signal and the val attribute selects single / double / singleAccounting / doubleAccounting). A <xf> record in <cellXfs> then points at that fontId. The assertion here checks the simpler shape: at least one <font> in xl/styles.xml contains a <u> child. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x'). Content of cell A1 appears in xl/sharedStrings.xml as an <si><t>Hello underline cell</t></si> entry.