| name | xlsx-parsing |
| description | Read Microsoft Excel (.xlsx) files robustly with `openpyxl` (or `pandas`). Covers multi-sheet workbooks, header rows, empty cells, merged cells, comma-separated list cells, and converting a sheet to a list-of-dicts the rest of your code can consume. Use when a task input or reference document is an `.xlsx` file rather than JSON/CSV. |
xlsx-parsing
Excel workbooks are the lingua franca of operational documents that nobody bothered to put in a database — playbooks, rate cards, deviation policies, finance models, SLAs. They show up in tasks with three properties that trip up naive readers:
- Multiple sheets, only one of which is the data you actually want.
- Sparse cells — a row that uses a column may sit next to a row that doesn't, leaving
None cells. Empty is meaningful (the rule does not apply), not an error.
- Composite cells — a single cell that contains a comma-separated list, a JSON blob, or a sentence rather than an atomic value.
Treat the workbook as a typed table with declared columns, not a free-form spreadsheet. Read every sheet you need, normalise it to list[dict[str, Any]], then operate on that.
Reading with openpyxl (pure Python, no compiled dependencies)
import openpyxl
wb = openpyxl.load_workbook("workbook.xlsx", data_only=True, read_only=True)
print(wb.sheetnames)
ws = wb["Rules"]
rows = ws.iter_rows(values_only=True)
header = [str(c).strip() if c c (rows)]
records = [((header, row)) row rows (cell cell row)]