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: —
| Feature id | xlsx/cell-font-color--purple |
|---|---|
| Format | xlsx |
| Category | cell-formatting |
| Family | xlsx/cell-font-color |
| Axis values | color=purple |
| Spec | ecma-376-5-part-1 § 18.8.3 color |
| ID / part | Predicate | XPath | python-xlsx | xlsxjs |
|---|---|---|---|---|
font-color-rgb-purplexl/styles.xml | match = ^[0-9A-Fa-f]{0,2}7F00FF$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 | — | — |
| ID | Predicate | Selector | python-xlsx | xlsxjs |
|---|---|---|---|---|
cell-font-color-purple-cell-present | css_selector/ existThe rendered sheet must contain the coloured cell. | section.xlsx td | — | — |
sheet-count-purple | css_selector/ equal-countExactly one rendered sheet section per case. Catches renderers that emit zero sheets (hard failure). | section.xlsx | — | — |
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())
{
"$schema": "../manifest.schema.json",
"id": "xlsx/cell-font-color--purple",
"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--purple"
},
"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": "purple"
}
},
"assertions": [
{
"id": "font-color-rgb-purple",
"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}7F00FF$",
"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-purple-cell-present",
"kind": "css_selector",
"selector": "section.xlsx td",
"must": "exist",
"description": "The rendered sheet must contain the coloured cell."
},
{
"id": "sheet-count-purple",
"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)."
}
]
}
