xlsx/data-validation-type--time

A worksheet declares a single <dataValidation> over A1:A10 whose @type takes each of the seven ST_DataValidationType values supported by python-xlsx: whole, decimal, list, date, time, textLength, and custom.

Library verdicts: python-xlsx: — xlsxjs: —

Metadata

Feature idxlsx/data-validation-type--time
Formatxlsx
Categorycell-data
Familyxlsx/data-validation-type
Axis valuestype=time
Spececma-376-5-part-1 § 18.3.1.32 dataValidation

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
validation-type-is-time
xl/worksheets/sheet1.xml
equal = time
The worksheet must contain a <dataValidations>/<dataValidation> whose @type equals the expected ST_DataValidationType enum value.
//x:dataValidations/x:dataValidation/@type

Render assertions

No render assertions declared.

Generator source

scripts/gen_data_validation_type.py

#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/data-validation-type--<id>.xlsx`` fixtures.

Parameterised family exercising the seven ``dataValidation`` ``@type``
values that python-xlsx supports via ``xlsx.worksheet.datavalidation.
DataValidation`` — ``whole``, ``decimal``, ``list``, ``date``, ``time``,
``textLength``, and ``custom``.

Each invocation writes a one-sheet workbook with ``A1`` populated, a
single ``DataValidation`` of the requested ``@type`` (with the requested
``formula1`` and optional ``formula2`` operand strings), and that
validation applied to ``A1:A10``. python-xlsx takes the formula strings
opaquely — the fixture preserves whatever shape the caller supplies. The
manifest at ``features/xlsx/data-validation-type.json`` drives the
parameter expansion.
"""

from __future__ import annotations

import argparse
import datetime as _dt
from pathlib import Path

from xlsx import Workbook
from xlsx.worksheet.datavalidation import DataValidation

_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(
        "--type",
        required=True,
        help="ST_DataValidationType value (whole|decimal|list|date|time|textLength|custom).",
    )
    parser.add_argument("--formula1", required=True, help="Primary operand expression.")
    parser.add_argument(
        "--formula2",
        default="",
        help="Secondary operand expression (empty string to omit).",
    )
    parser.add_argument("--out", required=True, help="Output .xlsx path.")
    args = parser.parse_args()

    out_path = Path(args.out)
    if not out_path.is_absolute():
        out_path = _REPO_ROOT / out_path
    out_path.parent.mkdir(parents=True, exist_ok=True)

    wb = Workbook()
    ws = wb.active
    ws["A1"] = "validated cell"

    dv_kwargs: dict[str, str] = {
        "type": args.type,
        "formula1": args.formula1,
    }
    if args.formula2:
        dv_kwargs["formula2"] = args.formula2
    dv = DataValidation(**dv_kwargs)
    dv.add("A1:A10")
    ws.add_data_validation(dv)

    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/data-validation-type--time",
  "kind": "literal",
  "title": "Data validation type",
  "format": "xlsx",
  "category": "cell-data",
  "summary": "A worksheet declares a single <dataValidation> over A1:A10 whose @type takes each of the seven ST_DataValidationType values supported by python-xlsx: whole, decimal, list, date, time, textLength, and custom.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "18.3.1.32",
    "element": "dataValidation",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
    "notes": "Data validation rules live inside <dataValidations> on a worksheet. Each <dataValidation> carries an @type drawn from ST_DataValidationType (ECMA-376 Part 1 18.18.20) — whole, decimal, list, date, time, textLength, or custom — plus optional <formula1> and <formula2> children that carry the operand expressions. python-xlsx's DataValidation accepts formula1/formula2 as opaque strings, so date and time formulas are passed through as ISO-style literal strings; Excel itself coerces these at open time. The 'custom' type semantically takes only formula1 (a predicate expression); we omit formula2 for that case. SpreadsheetML parts use a default namespace with no prefix; XPath binds it as 'x'."
  },
  "fixtures": {
    "machine": "xlsx/data-validation-type--time"
  },
  "generator": {
    "python": "scripts/gen_data_validation_type.py",
    "arg_template": "--type {type.val} --formula1 \"{type.formula1}\" --formula2 \"{type.formula2}\" --out fixtures/xlsx/data-validation-type--{type.id}.xlsx"
  },
  "_expansion": {
    "parent_id": "xlsx/data-validation-type",
    "bindings": {
      "type": "time"
    }
  },
  "assertions": [
    {
      "id": "validation-type-is-time",
      "part": "xl/worksheets/sheet1.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:dataValidations/x:dataValidation/@type",
      "must": "equal",
      "value": "time",
      "description": "The worksheet must contain a <dataValidations>/<dataValidation> whose @type equals the expected ST_DataValidationType enum value."
    }
  ]
}

Fixture

Download data-validation-type--time.xlsx (4.8 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/data-validation-type--time page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Data validation rules live inside <dataValidations> on a worksheet. Each <dataValidation> carries an @type drawn from ST_DataValidationType (ECMA-376 Part 1 18.18.20) — whole, decimal, list, date, time, textLength, or custom — plus optional <formula1> and <formula2> children that carry the operand expressions. python-xlsx's DataValidation accepts formula1/formula2 as opaque strings, so date and time formulas are passed through as ISO-style literal strings; Excel itself coerces these at open time. The 'custom' type semantically takes only formula1 (a predicate expression); we omit formula2 for that case. SpreadsheetML parts use a default namespace with no prefix; XPath binds it as 'x'.