code / legex /pdf_export /workbook.py
anonymous
[code] Initial release of the code.
6f5156a
raw
history blame contribute delete
710 Bytes
"""Goldenset workbook helpers."""
from __future__ import annotations
from pathlib import Path
def discover_goldensets(data_dir: Path) -> list[Path]:
"""Workbooks under ``data/<anything>/Goldenset_*.xlsx``."""
return sorted(data_dir.glob("*/Goldenset_*.xlsx"))
def header_map(header_row: tuple) -> dict[str, int]:
m: dict[str, int] = {}
for i, h in enumerate(header_row):
if h is None:
continue
m[str(h).strip().lower()] = i
return m
def cell(row: tuple, idx: int | None) -> str | None:
if idx is None:
return None
if idx < 0 or idx >= len(row):
return None
v = row[idx]
if v is None:
return None
return str(v)