Metadata-Version: 2.4
Name: xlsxflat
Version: 0.1.0
Summary: Turn a tree of messy .xlsx reports into one flat table, with a report of every change.
Author: Younes Z.
License: MIT
Project-URL: Homepage, https://github.com/Rezarys/xlsxflat
Project-URL: Issues, https://github.com/Rezarys/xlsxflat/issues
Keywords: excel,xlsx,spreadsheet,csv,data cleaning,provenance
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Office/Business :: Financial :: Spreadsheet
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openpyxl>=3.1
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Dynamic: license-file

# xlsxflat

For the person who keeps writing a throwaway script to turn a year and month tree of spreadsheet "reports" back into a table. It reads the tree, writes one flat CSV, and writes a report of every change it made. When a sheet can be read in more than one defensible way, it skips that sheet and says why, instead of guessing.

```
pip install xlsxflat==0.1.0
```

```
xlsxflat ./reports -o table.csv --report changes.md
```

```
xlsxflat: 4 rows to table.csv, 2 sheet(s) skipped
  skipped 2026/02/sites.xlsx/Summary: row 1 is written across several columns by a merged range, so it may be the upper half of a two level header; pass --header-row to say which row names the columns
  skipped 2026/03/sites.xlsx/Sheet2: header row 1 names the same column twice: ['site']
```

That block is the real output of a run, produced by a test so that it cannot drift from the code.

## What it does to a sheet

- the header is the first row whose filled cells are all text and that fills at least two columns, or the only column when the sheet has one
- repeats the value of a merged range over the whole range, so a label that covered six rows is on all six
- drops rows and columns that hold nothing at all
- keeps the original place of every value: each written row carries `source_file`, `source_sheet`, `source_row` and `period`
- reads a period out of the path below the folder you walked, when it is there: `2026/03/`, `2025_11 archive`, `2024`
- unions columns across files instead of dropping the odd one out

## What it refuses to do

It never guesses a shape. A sheet is skipped, with the reason written in the report, when:

- a row that looks like the header is written across several columns by a merged range, so it may be the upper half of a two level header
- the header names the same column twice
- the header leaves a column without a text name, while that column holds values
- the header uses one of `source_file`, `source_sheet`, `source_row`, `period`, which would be overwritten
- no row reads as a header at all
- the sheet holds no value at all, which is what an untouched default sheet looks like
- `--header-row N` was given and that row is empty in this sheet
- the file could not be opened at all

`--header-row N` answers the first case and the sheet goes through.

## Exit codes

| code | meaning |
|---|---|
| 0 | finished; read the report for skipped sheets |
| 2 | the target does not exist |
| 3 | `--strict`, and a sheet was skipped |
| 4 | the target is not an `.xlsx` and holds none |

`--strict` is for a pipeline that must stop on a skipped sheet. Note that an empty default sheet counts as skipped, so a tree full of workbooks with a leftover `Sheet1` will trip it.

## Limits worth knowing before you install

- column names are matched exactly, so `Site` and `site` come out as two columns
- it reads `.xlsx` only: not `.xls`, not `.csv`, not Google Sheets
- your workbooks are never written to: nothing is ever saved back, and a test compares the file bytes before and after
- it says nothing about whether your data is right; it says what the file held and what was done to it
- `openpyxl` is the only dependency, and every date cell is written as ISO text

## Price

The tool is free and MIT. There is nothing to buy today and no payment can be taken. If a supported build would be worth something to you, open an issue on the repository and it will be read.

## Install from source

```
git clone https://github.com/Rezarys/xlsxflat
cd xlsxflat
pip install -e ".[dev]"
python -m pytest
```

## Notes

Built with AI assistance, reviewed and tested by me. Bug reports are welcome, especially a sheet shape that should be read and is skipped, or the reverse.

MIT, Younes Z.
