xlsx/interop-cell-formats--thousands-right-bold

A curated set of (number-format, alignment, font-size, bold) combinations applied to cell A1. python-xlsx authors each fixture; xlsxjs renders it. The manifest asserts both that the correct cellXfs entries are written AND that xlsxjs renders the corresponding formatted text + CSS. Catches cases where python-xlsx writes format id 14 but xlsxjs shows a raw serial number, or where a bold/alignment style is silently dropped on render.

Library verdicts: python-xlsx: — xlsxjs: —

Metadata

Feature idxlsx/interop-cell-formats--thousands-right-bold
Formatxlsx
Categoryinterop
Familyxlsx/interop-cell-formats
Axis valuescombo=thousands-right-bold
Spececma-376-5-part-1 § 18.8 cellXfs

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
cell-xf-references-numfmt-thousands-right-bold
xl/styles.xml
exist
A <xf> in <cellXfs> must reference numFmtId=3.
//x:cellXfs/x:xf[@numFmtId='3']
cell-has-value-thousands-right-bold
xl/worksheets/sheet1.xml
exist
Cell A1 must carry a stored value.
//x:c[@r='A1']/x:v

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
interop-cell-text-thousands-right-boldcss_selector/ match-text = ^1,234,567$
xlsxjs must render the formatted cell text matching the expected regex (not the raw serial/decimal value).
td, .xlsx-cell, [data-cell='A1']

Generator source

scripts/gen_interop_cell_formats.py

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

Parameterised generator for the ``xlsx/interop-cell-formats`` manifest
(Wave 5-C cross-library interop). Each expanded case sets a specific
combination of number-format, horizontal alignment, font size, and
bold-ness on cell A1 of a single-sheet workbook. The manifest asserts
both that python-xlsx writes the expected cellXfs entry AND that xlsxjs
renders the corresponding CSS/text in the HTML output.
"""

from __future__ import annotations

import argparse
import datetime as _dt
from pathlib import Path

from xlsx import Workbook
from xlsx.styles import Alignment, Font
from xlsx.styles.numbers import BUILTIN_FORMATS

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


def _to_bool(s: str) -> bool:
    return s.lower() in ("1", "true", "yes", "on")


def _coerce_value(raw: str) -> object:
    # Try int, then float, then leave as string.
    try:
        if raw.lstrip("-").isdigit():
            return int(raw)
        return float(raw)
    except ValueError:
        return raw


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--num-fmt-id", type=int, required=True)
    parser.add_argument("--horizontal", default="general")
    parser.add_argument("--font-size", type=float, default=11.0)
    parser.add_argument("--bold", default="false")
    parser.add_argument("--value", required=True)
    parser.add_argument("--out", required=True)
    args = parser.parse_args()

    if args.num_fmt_id not in BUILTIN_FORMATS:
        raise SystemExit(
            f"num_fmt_id {args.num_fmt_id} not a built-in; valid: {sorted(BUILTIN_FORMATS)}"
        )

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

    wb = Workbook()
    ws = wb.active
    ws["A1"] = _coerce_value(args.value)
    ws["A1"].number_format = BUILTIN_FORMATS[args.num_fmt_id]
    ws["A1"].alignment = Alignment(horizontal=args.horizontal)
    ws["A1"].font = Font(size=args.font_size, bold=_to_bool(args.bold))

    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/interop-cell-formats--thousands-right-bold",
  "kind": "literal",
  "title": "Cross-library cell formats (python-xlsx -> xlsxjs)",
  "format": "xlsx",
  "category": "interop",
  "summary": "A curated set of (number-format, alignment, font-size, bold) combinations applied to cell A1. python-xlsx authors each fixture; xlsxjs renders it. The manifest asserts both that the correct cellXfs entries are written AND that xlsxjs renders the corresponding formatted text + CSS. Catches cases where python-xlsx writes format id 14 but xlsxjs shows a raw serial number, or where a bold/alignment style is silently dropped on render.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "18.8",
    "element": "cellXfs",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
    "notes": "A cell's presentation is the join of (a) the cell's numeric/text value in <c><v>, (b) a reference from <c>/@s into <cellXfs>/<xf>, and (c) the <xf>'s references into <numFmts>, <fonts>, <alignment>, etc. Built-in numFmtIds (0-49) are NEVER written into <numFmts>; xlsxjs must recognise them by id alone. This interop family checks that python-xlsx's stylesheet composition AND xlsxjs's style-lookup-on-render agree for common combinations."
  },
  "fixtures": {
    "machine": "xlsx/interop-cell-formats--thousands-right-bold"
  },
  "generator": {
    "python": "scripts/gen_interop_cell_formats.py",
    "arg_template": "--num-fmt-id {combo.num_fmt_id} --horizontal {combo.horizontal} --font-size {combo.font_size} --bold {combo.bold} --value \"{combo.value}\" --out fixtures/xlsx/interop-cell-formats--{combo.id}.xlsx"
  },
  "_expansion": {
    "parent_id": "xlsx/interop-cell-formats",
    "bindings": {
      "combo": "thousands-right-bold"
    }
  },
  "assertions": [
    {
      "id": "cell-xf-references-numfmt-thousands-right-bold",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:cellXfs/x:xf[@numFmtId='3']",
      "must": "exist",
      "description": "A <xf> in <cellXfs> must reference numFmtId=3."
    },
    {
      "id": "cell-has-value-thousands-right-bold",
      "part": "xl/worksheets/sheet1.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:c[@r='A1']/x:v",
      "must": "exist",
      "description": "Cell A1 must carry a stored value."
    }
  ],
  "render_assertions": [
    {
      "id": "interop-cell-text-thousands-right-bold",
      "kind": "css_selector",
      "selector": "td, .xlsx-cell, [data-cell='A1']",
      "must": "match-text",
      "value": "^1,234,567$",
      "description": "xlsxjs must render the formatted cell text matching the expected regex (not the raw serial/decimal value)."
    }
  ]
}

Fixture

Download interop-cell-formats--thousands-right-bold.xlsx (4.8 KB)

Reference preview

No rendered reference is available for this case.

Spec notes

A cell's presentation is the join of (a) the cell's numeric/text value in <c><v>, (b) a reference from <c>/@s into <cellXfs>/<xf>, and (c) the <xf>'s references into <numFmts>, <fonts>, <alignment>, etc. Built-in numFmtIds (0-49) are NEVER written into <numFmts>; xlsxjs must recognise them by id alone. This interop family checks that python-xlsx's stylesheet composition AND xlsxjs's style-lookup-on-render agree for common combinations.