Apply an explicit font size in points to a cell's font; the size appears in xl/styles.xml as a <font>/<sz>/@val entry.
| Library | Pass | Fail | Pending |
|---|---|---|---|
python-xlsx | 0 | 0 | 10 |
xlsxjs | 0 | 0 | 10 |
size (10 values): pt06, pt08, pt10, pt11, pt12, pt14, pt16, pt18, pt24, pt36scripts/gen_cell_font_size.py — runs with --arg_template --pt {size.pt} --text "{size.text}" --out fixtures/xlsx/cell-font-size--{size.id}.xlsx
#!/usr/bin/env python3
"""Generate a ``fixtures/xlsx/cell-font-size--<id>.xlsx`` fixture.
Parameterised generator for the ``xlsx/cell-font-size`` manifest.
Writes a minimal one-sheet workbook with cell A1 carrying a text value
and a ``Font(size=pt)`` applied to it. python-xlsx emits the size as
``<sz val="N"/>`` on the font entry in xl/styles.xml.
"""
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("--pt", type=float, required=True, help="Font size in points")
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
# xlsx writes the float verbatim; pass ints as ints to avoid "10.0"
pt: float | int = args.pt
if pt.is_integer():
pt = int(pt)
wb = Workbook()
ws = wb.active
ws["A1"] = args.text
ws["A1"].font = Font(size=pt)
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-size",
"kind": "parameterised",
"title": "Cell font size (10 point sizes)",
"format": "xlsx",
"category": "cell-formatting",
"summary": "Apply an explicit font size in points to a cell's font; the size appears in xl/styles.xml as a <font>/<sz>/@val entry.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "18.8.26",
"element": "sz",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
"notes": "SpreadsheetML encodes font size on a <font> entry in xl/styles.xml's <fonts> table as a <sz val=\"N\"/> child where N is the size in POINTS (decimal, not half-points — unlike WordprocessingML). ECMA-376 Part 1 clause 18.8.26 defines CT_FontSize / ST_FontSize. python-xlsx's default Calibri font carries <sz val=\"11\"/>; a user-applied Font(size=N) adds a second <font> entry whose children are limited to <sz> (no <name>/<family>/<color>/<scheme>). The manifest's XPath therefore selects ``//x:fonts/x:font[not(x:name)]/x:sz/@val`` to target only the custom font and ignore the default, so the sz=11 fixture also asserts correctly. SpreadsheetML parts use a default namespace with no prefix; XPath needs an explicit binding (here 'x'). One manifest file expands into 10 concrete fixture cases (6/8/10/11/12/14/16/18/24/36 pt)."
},
"fixtures": {
"machine": "xlsx/cell-font-size"
},
"generator": {
"python": "scripts/gen_cell_font_size.py",
"arg_template": "--pt {size.pt} --text \"{size.text}\" --out fixtures/xlsx/cell-font-size--{size.id}.xlsx"
},
"parameters": {
"size": [
{
"id": "pt06",
"pt": 6,
"text": "Size 6 pt"
},
{
"id": "pt08",
"pt": 8,
"text": "Size 8 pt"
},
{
"id": "pt10",
"pt": 10,
"text": "Size 10 pt"
},
{
"id": "pt11",
"pt": 11,
"text": "Size 11 pt"
},
{
"id": "pt12",
"pt": 12,
"text": "Size 12 pt"
},
{
"id": "pt14",
"pt": 14,
"text": "Size 14 pt"
},
{
"id": "pt16",
"pt": 16,
"text": "Size 16 pt"
},
{
"id": "pt18",
"pt": 18,
"text": "Size 18 pt"
},
{
"id": "pt24",
"pt": 24,
"text": "Size 24 pt"
},
{
"id": "pt36",
"pt": 36,
"text": "Size 36 pt"
}
]
},
"assertions_template": [
{
"id": "font-size-val-{size.id}",
"part": "xl/styles.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:fonts/x:font[not(x:name)]/x:sz/@val",
"must": "equal",
"value": "{size.pt}",
"description": "A <sz>/@val under the custom <font> (i.e. the one without a <name> child) in xl/styles.xml must carry the point size. SpreadsheetML encodes sz in points (not half-points)."
}
],
"render_assertions_template": [
{
"id": "cell-font-size-{size.id}-cell-present",
"kind": "css_selector",
"selector": "section.xlsx td",
"must": "exist",
"description": "The rendered sheet must contain the sized cell."
},
{
"id": "sheet-count-{size.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)."
}
]
}