xlsx/cell-font-size--pt11

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 verdicts: python-xlsx: — xlsxjs: —

Metadata

Feature idxlsx/cell-font-size--pt11
Formatxlsx
Categorycell-formatting
Familyxlsx/cell-font-size
Axis valuessize=pt11
Spececma-376-5-part-1 § 18.8.26 sz

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
font-size-val-pt11
xl/styles.xml
equal = 11
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).
//x:fonts/x:font[not(x:name)]/x:sz/@val

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
cell-font-size-pt11-cell-presentcss_selector/ exist
The rendered sheet must contain the sized cell.
section.xlsx td
sheet-count-pt11css_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_size.py

#!/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())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/cell-font-size--pt11",
  "kind": "literal",
  "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--pt11"
  },
  "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"
  },
  "_expansion": {
    "parent_id": "xlsx/cell-font-size",
    "bindings": {
      "size": "pt11"
    }
  },
  "assertions": [
    {
      "id": "font-size-val-pt11",
      "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": "11",
      "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": [
    {
      "id": "cell-font-size-pt11-cell-present",
      "kind": "css_selector",
      "selector": "section.xlsx td",
      "must": "exist",
      "description": "The rendered sheet must contain the sized cell."
    },
    {
      "id": "sheet-count-pt11",
      "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-size--pt11.xlsx (4.7 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/cell-font-size--pt11 page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec 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).