A workbook applies a <patternFill> to cell A1 using each of the 16 ST_PatternType values that carry foreground/background colours, paired with five colour families.
| Library | Pass | Fail | Pending |
|---|---|---|---|
python-xlsx | 0 | 0 | 80 |
xlsxjs | 80 | 0 | 0 |
pattern (16 values): solid, medium-gray, dark-gray, light-gray, dark-horizontal, dark-vertical, dark-down, dark-up, dark-grid, dark-trellis, light-horizontal, light-vertical, light-down, light-up, light-grid, light-trelliscolor (5 values): red-white, blue-yellow, black-white, green-white, purple-whitescripts/gen_cell_fill_pattern.py — runs with --arg_template --pattern {pattern.val} --fg {color.fg} --bg {color.bg} --out fixtures/xlsx/cell-fill-pattern--{color.id}--{pattern.id}.xlsx
#!/usr/bin/env python3
"""Generate a fixtures/xlsx/cell-fill-pattern--<color>--<pattern>.xlsx fixture."""
from __future__ import annotations
import argparse
import datetime as _dt
from pathlib import Path
from xlsx import Workbook
from xlsx.styles import PatternFill
_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("--pattern", required=True)
parser.add_argument("--fg", required=True)
parser.add_argument("--bg", required=True)
parser.add_argument("--out", required=True)
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"] = "Filled cell"
ws["A1"].fill = PatternFill(
patternType=args.pattern,
fgColor=args.fg,
bgColor=args.bg,
)
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-fill-pattern",
"kind": "parameterised",
"title": "Cell fill pattern (16 ST_PatternType values x 5 colour pairs)",
"format": "xlsx",
"category": "cell-formatting",
"summary": "A workbook applies a <patternFill> to cell A1 using each of the 16 ST_PatternType values that carry foreground/background colours, paired with five colour families.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "18.8.20",
"element": "patternFill",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
"notes": "ST_PatternType (ECMA-376 Part 1 clause 18.18.55) defines 19 pattern type values for <patternFill>. This manifest covers the 16 that accept foreground and background colours: solid, mediumGray, darkGray, lightGray, darkHorizontal, darkVertical, darkDown, darkUp, darkGrid, darkTrellis, lightHorizontal, lightVertical, lightDown, lightUp, lightGrid, lightTrellis. The three omitted values (none, gray0625, gray125) are pattern-only and do not meaningfully carry colours. Each pattern is paired with five colour families (fg/bg hex pairs). One manifest file expands into 16 x 5 = 80 concrete fixture cases. Axis ordering is alphabetised by ooxml_validate.expand_manifest, so fixture names are `<id>--<color.id>--<pattern.id>`."
},
"fixtures": {
"machine": "xlsx/cell-fill-pattern"
},
"generator": {
"python": "scripts/gen_cell_fill_pattern.py",
"arg_template": "--pattern {pattern.val} --fg {color.fg} --bg {color.bg} --out fixtures/xlsx/cell-fill-pattern--{color.id}--{pattern.id}.xlsx"
},
"parameters": {
"pattern": [
{
"id": "solid",
"val": "solid"
},
{
"id": "medium-gray",
"val": "mediumGray"
},
{
"id": "dark-gray",
"val": "darkGray"
},
{
"id": "light-gray",
"val": "lightGray"
},
{
"id": "dark-horizontal",
"val": "darkHorizontal"
},
{
"id": "dark-vertical",
"val": "darkVertical"
},
{
"id": "dark-down",
"val": "darkDown"
},
{
"id": "dark-up",
"val": "darkUp"
},
{
"id": "dark-grid",
"val": "darkGrid"
},
{
"id": "dark-trellis",
"val": "darkTrellis"
},
{
"id": "light-horizontal",
"val": "lightHorizontal"
},
{
"id": "light-vertical",
"val": "lightVertical"
},
{
"id": "light-down",
"val": "lightDown"
},
{
"id": "light-up",
"val": "lightUp"
},
{
"id": "light-grid",
"val": "lightGrid"
},
{
"id": "light-trellis",
"val": "lightTrellis"
}
],
"color": [
{
"id": "red-white",
"fg": "FF0000",
"bg": "FFFFFF"
},
{
"id": "blue-yellow",
"fg": "0000FF",
"bg": "FFFF00"
},
{
"id": "black-white",
"fg": "000000",
"bg": "FFFFFF"
},
{
"id": "green-white",
"fg": "00FF00",
"bg": "FFFFFF"
},
{
"id": "purple-white",
"fg": "800080",
"bg": "FFFFFF"
}
]
},
"assertions_template": [
{
"id": "pattern-{pattern.id}-{color.id}",
"part": "xl/styles.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:fills/x:fill/x:patternFill[@patternType='{pattern.val}']",
"must": "exist",
"description": "The styles part must contain a <patternFill> with the expected ST_PatternType value."
}
],
"render_assertions_template": [
{
"id": "cell-text-{pattern.id}-{color.id}",
"kind": "css_selector",
"selector": "section.xlsx td",
"must": "exist",
"description": "The rendered sheet must contain the cell with the pattern fill applied."
},
{
"id": "sheet-count-{pattern.id}",
"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)."
}
]
}