xlsx/cell-percentage

A workbook with A1=0.25 formatted as '0.00%' renders as 25.00%; the format code is one of Excel's built-in numFmtIds so the styles part references it via a <cellXfs>/<xf numFmtId=.../> without an accompanying <numFmts> entry.

Library verdicts: python-xlsx: — xlsxjs: pass

Metadata

Feature idxlsx/cell-percentage
Formatxlsx
Categorycell-data
Spececma-376-5-part-1 § 18.8.30 numFmt

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
percentage-cell-value
xl/worksheets/sheet1.xml
exist
The A1 cell must carry the raw numeric value 0.25 — the percentage display is a format-time transformation, not a stored string.
//x:c[@r='A1']/x:v[normalize-space()='0.25']
percentage-xf-references-builtin-10
xl/styles.xml
exist
At least one <xf> in <cellXfs> must reference numFmtId=10 — the built-in '0.00%' format. Writers that emit a custom <numFmt formatCode='0.00%'/> would fail this assertion; that is the correct behaviour because Excel itself uses the built-in id.
//x:cellXfs/x:xf[@numFmtId='10']

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
cell-percentage-text-presentcss_selector/ match-text = ^(25(?:\.0{1,2})?%|0\.25)$
The rendered sheet must contain a cell showing either the formatted percentage (25%, 25.0%, 25.00%) or the raw value (0.25) if the renderer does not apply numFmt transforms.
section.xlsx td, section.xlsx thpass
sheet-countcss_selector/ equal-count
Exactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet.
section.xlsx

Generator source

scripts/gen_cell_percentage.py

#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/cell-percentage.xlsx``.

A minimal one-sheet workbook with cell A1 carrying the raw numeric
value 0.25 and number_format '0.00%', which resolves to Excel's
built-in numFmtId=10. Designed to satisfy the assertions in
``features/xlsx/cell-percentage.json``.
"""

from __future__ import annotations

from pathlib import Path

from xlsx import Workbook

import datetime as _dt
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)

_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "xlsx" / "cell-percentage.xlsx"


def main() -> int:
    wb = Workbook()
    ws = wb.active
    ws["A1"] = 0.25
    ws["A1"].number_format = "0.00%"
    _OUT.parent.mkdir(parents=True, exist_ok=True)
    wb.save(_OUT, zip_date_time=_REPRODUCIBLE_DT)
    print(_OUT)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/cell-percentage",
  "title": "Percentage-formatted cell",
  "format": "xlsx",
  "category": "cell-data",
  "summary": "A workbook with A1=0.25 formatted as '0.00%' renders as 25.00%; the format code is one of Excel's built-in numFmtIds so the styles part references it via a <cellXfs>/<xf numFmtId=.../> without an accompanying <numFmts> entry.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "18.8.30",
    "element": "numFmt",
    "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.30 defines <numFmt> and tables the built-in format IDs. '0.00%' is built-in numFmtId=10, so compliant writers (python-xlsx, Excel) do NOT emit a custom <numFmt> for it — they just reference numFmtId=10 from <cellXfs>/<xf>. The canonical test therefore checks for at least one <xf> in <cellXfs> with numFmtId='10', NOT the presence of a <numFmt formatCode='0.00%'/>. A stored value of 0.25 combined with numFmtId=10 is what Excel renders as '25.00%'. SpreadsheetML parts use a default namespace with no prefix; XPath needs an explicit binding (here 'x')."
  },
  "fixtures": {
    "machine": "xlsx/cell-percentage",
    "office": "xlsx/cell-percentage"
  },
  "generator": {
    "python": "scripts/gen_cell_percentage.py"
  },
  "assertions": [
    {
      "id": "percentage-cell-value",
      "part": "xl/worksheets/sheet1.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:c[@r='A1']/x:v[normalize-space()='0.25']",
      "must": "exist",
      "description": "The A1 cell must carry the raw numeric value 0.25 — the percentage display is a format-time transformation, not a stored string."
    },
    {
      "id": "percentage-xf-references-builtin-10",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:cellXfs/x:xf[@numFmtId='10']",
      "must": "exist",
      "description": "At least one <xf> in <cellXfs> must reference numFmtId=10 — the built-in '0.00%' format. Writers that emit a custom <numFmt formatCode='0.00%'/> would fail this assertion; that is the correct behaviour because Excel itself uses the built-in id."
    }
  ],
  "render_assertions": [
    {
      "id": "cell-percentage-text-present",
      "kind": "css_selector",
      "selector": "section.xlsx td, section.xlsx th",
      "must": "match-text",
      "value": "^(25(?:\\.0{1,2})?%|0\\.25)$",
      "description": "The rendered sheet must contain a cell showing either the formatted percentage (25%, 25.0%, 25.00%) or the raw value (0.25) if the renderer does not apply numFmt transforms."
    },
    {
      "id": "sheet-count",
      "kind": "css_selector",
      "selector": "section.xlsx",
      "must": "equal-count",
      "count": 1,
      "description": "Exactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet."
    }
  ]
}

Fixture

Download cell-percentage.xlsx (4.7 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/cell-percentage page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

ECMA-376 Part 1 clause 18.8.30 defines <numFmt> and tables the built-in format IDs. '0.00%' is built-in numFmtId=10, so compliant writers (python-xlsx, Excel) do NOT emit a custom <numFmt> for it — they just reference numFmtId=10 from <cellXfs>/<xf>. The canonical test therefore checks for at least one <xf> in <cellXfs> with numFmtId='10', NOT the presence of a <numFmt formatCode='0.00%'/>. A stored value of 0.25 combined with numFmtId=10 is what Excel renders as '25.00%'. SpreadsheetML parts use a default namespace with no prefix; XPath needs an explicit binding (here 'x').