xlsx/cell-number

A workbook carries a numeric value in cell A1 as a raw <v> child of the cell element in the worksheet part.

Library verdicts: python-xlsx: — xlsxjs: pass

Metadata

Feature idxlsx/cell-number
Formatxlsx
Categorycell-data
Spececma-376-5-part-1 § 18.3.1.4 c

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
number-cell-value
xl/worksheets/sheet1.xml
exist
The A1 cell in the first worksheet must have a <v> child whose text is the number 42.5.
//x:c[@r='A1']/x:v[normalize-space()='42.5']

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
cell-number-text-presentcss_selector/ match-text = 42(?:\.5[0-9]*|\.5)?
The rendered sheet must contain a cell showing the number 42.5. Renderers may format with or without trailing zeros (42.5, 42.50, 42.500) — the regex accepts the common variants.
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_number.py

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

A minimal one-sheet workbook with cell A1 containing the numeric value 42.5.
Designed to satisfy the assertions in ``features/xlsx/cell-number.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-number.xlsx"


def main() -> int:
    wb = Workbook()
    ws = wb.active
    ws["A1"] = 42.5
    _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-number",
  "title": "Numeric cell value",
  "format": "xlsx",
  "category": "cell-data",
  "summary": "A workbook carries a numeric value in cell A1 as a raw <v> child of the cell element in the worksheet part.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "18.3.1.4",
    "element": "c",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
    "notes": "Numeric cell values in SpreadsheetML live inside a <c> element as a <v> child whose text is the number's string form. The default cell type is numeric, so the <c t=\"...\"/> attribute is optional for numbers (python-xlsx emits t=\"n\" explicitly, Excel often omits it — both shapes are spec-valid). The assertion here targets the minimal universal shape: <c r=\"A1\"> contains <v>42.5</v>. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x')."
  },
  "fixtures": {
    "machine": "xlsx/cell-number",
    "office": "xlsx/cell-number"
  },
  "generator": {
    "python": "scripts/gen_cell_number.py"
  },
  "assertions": [
    {
      "id": "number-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()='42.5']",
      "must": "exist",
      "description": "The A1 cell in the first worksheet must have a <v> child whose text is the number 42.5."
    }
  ],
  "render_assertions": [
    {
      "id": "cell-number-text-present",
      "kind": "css_selector",
      "selector": "section.xlsx td, section.xlsx th",
      "must": "match-text",
      "value": "42(?:\\.5[0-9]*|\\.5)?",
      "description": "The rendered sheet must contain a cell showing the number 42.5. Renderers may format with or without trailing zeros (42.5, 42.50, 42.500) — the regex accepts the common variants."
    },
    {
      "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-number.xlsx (4.7 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/cell-number page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Numeric cell values in SpreadsheetML live inside a <c> element as a <v> child whose text is the number's string form. The default cell type is numeric, so the <c t="..."/> attribute is optional for numbers (python-xlsx emits t="n" explicitly, Excel often omits it — both shapes are spec-valid). The assertion here targets the minimal universal shape: <c r="A1"> contains <v>42.5</v>. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x').