xlsx/cell-font-color--yellow

Apply an explicit RGB foreground colour to a cell's font; the colour appears in xl/styles.xml as a <font>/<color>/@rgb entry.

Library verdicts: python-xlsx: — xlsxjs: —

Metadata

Feature idxlsx/cell-font-color--yellow
Formatxlsx
Categorycell-formatting
Familyxlsx/cell-font-color
Axis valuescolor=yellow
Spececma-376-5-part-1 § 18.8.3 color

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
font-color-rgb-yellow
xl/styles.xml
match = ^[0-9A-Fa-f]{0,2}FFFF00$
A <font>/<color>/@rgb in xl/styles.xml must carry the expected colour. The ARGB representation tolerates an optional two-hex-digit alpha prefix (python-xlsx emits ``00``; Excel emits ``FF``).
//x:fonts/x:font/x:color/@rgb

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
cell-font-color-yellow-cell-presentcss_selector/ exist
The rendered sheet must contain the coloured cell.
section.xlsx td
sheet-count-yellowcss_selector/ equal-count
Exactly one rendered sheet section per case. Catches renderers that emit zero sheets (hard failure).
section.xlsx

Generator source

scripts/gen_cell_font_color.py

#!/usr/bin/env python3
"""Generate a ``fixtures/xlsx/cell-font-color--<id>.xlsx`` fixture.

Parameterised generator for the ``xlsx/cell-font-color`` manifest.
Writes a minimal one-sheet workbook with cell A1 carrying a text value
and a ``Font(color=rgb_hex)`` applied to it. python-xlsx emits the
colour as ``<color rgb="AARRGGBB"/>`` where the alpha prefix is ``00``
by default; the manifest assertion regex therefore tolerates an
optional two-hex-digit alpha prefix.
"""

from __future__ import annotations

import argparse
import datetime as _dt
from pathlib import Path

from xlsx import Workbook
from xlsx.styles import Font

_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)
_REPO_ROOT = Path(__file__).resolve().parent.parent


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--color-rgb", required=True, help="6 hex digits, RRGGBB")
    parser.add_argument("--text", required=True, help="Cell A1 contents")
    parser.add_argument("--out", required=True, help="Output fixture path")
    args = parser.parse_args()

    out_path = Path(args.out)
    if not out_path.is_absolute():
        out_path = _REPO_ROOT / out_path

    wb = Workbook()
    ws = wb.active
    ws["A1"] = args.text
    ws["A1"].font = Font(color=args.color_rgb)
    out_path.parent.mkdir(parents=True, exist_ok=True)
    wb.save(out_path, zip_date_time=_REPRODUCIBLE_DT)
    print(out_path)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/cell-font-color--yellow",
  "kind": "literal",
  "title": "Cell font colour (10 RGB values)",
  "format": "xlsx",
  "category": "cell-formatting",
  "summary": "Apply an explicit RGB foreground colour to a cell's font; the colour appears in xl/styles.xml as a <font>/<color>/@rgb entry.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "18.8.3",
    "element": "color",
    "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.8.3 / CT_Color permits @rgb to carry a colour as ARGB (8 hex digits). SpreadsheetML serialises foreground text colour on a <font> entry inside <fonts> in xl/styles.xml via a <color rgb=\"AARRGGBB\"/> child. python-xlsx synthesises the alpha channel as the literal prefix ``00`` when the caller supplies a 6-digit ``RRGGBB``; other writers (Excel) emit ``FF``. The manifest assertion regex therefore tolerates an optional two-hex-digit alpha prefix. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x'). One manifest file expands into 10 concrete fixture cases (the 10 RGB colours matching docx/font-color)."
  },
  "fixtures": {
    "machine": "xlsx/cell-font-color--yellow"
  },
  "generator": {
    "python": "scripts/gen_cell_font_color.py",
    "arg_template": "--color-rgb {color.rgb} --text \"{color.text}\" --out fixtures/xlsx/cell-font-color--{color.id}.xlsx"
  },
  "_expansion": {
    "parent_id": "xlsx/cell-font-color",
    "bindings": {
      "color": "yellow"
    }
  },
  "assertions": [
    {
      "id": "font-color-rgb-yellow",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:fonts/x:font/x:color/@rgb",
      "must": "match",
      "value": "^[0-9A-Fa-f]{0,2}FFFF00$",
      "description": "A <font>/<color>/@rgb in xl/styles.xml must carry the expected colour. The ARGB representation tolerates an optional two-hex-digit alpha prefix (python-xlsx emits ``00``; Excel emits ``FF``)."
    }
  ],
  "render_assertions": [
    {
      "id": "cell-font-color-yellow-cell-present",
      "kind": "css_selector",
      "selector": "section.xlsx td",
      "must": "exist",
      "description": "The rendered sheet must contain the coloured cell."
    },
    {
      "id": "sheet-count-yellow",
      "kind": "css_selector",
      "selector": "section.xlsx",
      "must": "equal-count",
      "count": 1,
      "description": "Exactly one rendered sheet section per case. Catches renderers that emit zero sheets (hard failure)."
    }
  ]
}

Fixture

Download cell-font-color--yellow.xlsx (4.7 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/cell-font-color--yellow page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

ECMA-376 Part 1 clause 18.8.3 / CT_Color permits @rgb to carry a colour as ARGB (8 hex digits). SpreadsheetML serialises foreground text colour on a <font> entry inside <fonts> in xl/styles.xml via a <color rgb="AARRGGBB"/> child. python-xlsx synthesises the alpha channel as the literal prefix ``00`` when the caller supplies a 6-digit ``RRGGBB``; other writers (Excel) emit ``FF``. The manifest assertion regex therefore tolerates an optional two-hex-digit alpha prefix. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x'). One manifest file expands into 10 concrete fixture cases (the 10 RGB colours matching docx/font-color).