Metadata-Version: 2.5
Name: sheetmap
Version: 0.1.0
Summary: Draw labelled cell ranges over Excel worksheets as PNGs and a standalone review page
Project-URL: Homepage, https://github.com/phlohouse/sheetmap
Project-URL: Repository, https://github.com/phlohouse/sheetmap
Project-URL: Issues, https://github.com/phlohouse/sheetmap/issues
Author: Phlo House
License-Expression: MIT
Keywords: excel,openpyxl,review,spreadsheet,visualisation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: File Formats
Classifier: Topic :: Office/Business :: Financial :: Spreadsheet
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: openpyxl<4,>=3.1
Requires-Dist: pillow<13,>=10.1
Requires-Dist: pyyaml<7,>=6.0
Description-Content-Type: text/markdown

# sheetmap

Draw labelled cell ranges over Excel worksheets. Each mapped sheet becomes a PNG showing its
contents, fills, borders and merged cells, with every region outlined and tagged with its label.
The PNGs are gathered into one standalone HTML page, side by side where they fit. With `--review`,
readers can also click a label to ask for a range to be removed or changed, then copy a summary of
their requests.

Use it to check that a parser, schema or extraction reads the cells you think it does, and to
let someone who knows the workbook review those choices without reading code.

## Run the example

From this folder:

```bash
uv run sheetmap examples/lab/map.yaml
```

Open `examples/lab/map.html`. The example workbook holds invented data.

To check a map against its workbook without writing anything, for example in CI:

```bash
uv run sheetmap check examples/lab/map.yaml
```

## Write a map

A map file names a workbook and the regions to label. Paths resolve relative to the map file.

```yaml
title: Lab report
workbook: january.xlsx
subtitle: January example
preview:
  Raw_Data: {rows: 12, columns: 6}
regions:
  - {label: patient, ref: "Report!B3"}
  - label: results
    ref: "Report!A7:D"
    columns: {A: sample_id, C: analyte, D: value}
  - {label: flags, ref: "Report!F8:F", kind: list}
  - {label: signals, ref: "Raw_Data!A1:D", kind: table}
```

Each region needs a `label`, unique within its map, and a `ref`:

| `ref` | Meaning |
| --- | --- |
| `B3` | One cell on the first worksheet |
| `Report!B3` | One cell on the `Report` sheet; quote names with spaces: `'Raw data'!B3` |
| `Report!A7:D20` | A rectangle |
| `Report!A7:D` | Open-ended: runs to the last row with a value in columns A to D |

A region can also take:

- `kind`: `cell`, `range`, `list` or `table`, which sets its colour. It defaults to `table` when
  `columns` or `rows` are given, `cell` for one cell and `range` otherwise.
- `columns`: labels for table columns, keyed by letter. A column without a label continues the
  label on its left when its cells are empty, so merged headers share one label. A column that has
  values but no label is an error, because it usually means the mapping has missed something.
- `rows`: labels for a table that reads across, keyed by row number. Give `columns` or `rows`,
  not both.
- `colour`: a hex colour such as `#be123c`, overriding the colour for its kind.

A label for one cell of a merged block highlights the whole block.

A map file can set `layout` and `review` for the page, as described below. A map can also take:

- `title` and `subtitle`, shown above each image. The title defaults to the workbook's name.
- `key`, which tells apart two maps with the same title. It defaults to the title and workbook name.
- `preview`, which limits named sheets to a number of `rows` and `columns`. The preview always
  includes the first row of every region; regions that run further are cut off.
- `details`, extra lines added to each review request, such as a schema path or version.
- `scope`, text for a checkbox reviewers can tick to say a request applies more widely, for
  example `Apply to every version of this schema`.

The page states each map's title once, and captions each image with its sheet, its number of regions
and any preview limit. The PNGs hold only the sheet, so they can be used on their own.

To put several workbooks on one page, list them under `maps:`, with an optional page `title`:

```yaml
title: Lab reports
maps:
  - {workbook: january.xlsx, regions: [...]}
  - {workbook: february.xlsx, regions: [...]}
```

You can also pass several map files: `sheetmap a.yaml b.yaml -o reports.html`.

## Lay out the page

Every image has two dimensions: the **map** it belongs to and the **sheet** it shows. A `layout`
block in the map file says which dimension forms the sections of the page, which forms the rows and
which forms the columns. Each dimension can be used once.

```yaml
layout:
  sections: sheet   # auto (the default), none, map or sheet
  rows: sheet       # map or sheet
  columns: map      # map or sheet
  wrap: 3           # flow into this many columns when rows and columns are not set
  fit: true         # scale grids to the window
```

Some useful layouts:

| Layout | Result |
| --- | --- |
| *(none)* | A section per map, with its sheets side by side while they fit |
| `columns: map` | A section per sheet, with a column per map lined up down the page; good for comparing examples |
| `columns: sheet` | A section per map, with a column per sheet lined up down the page |
| `rows: sheet`, `columns: map` | One table: a row per sheet, a column per map, with headings on both |
| `sections: none`, `wrap: 3` | Every image in one grid, three to a row |

`sections: auto` uses whichever dimension the rows and columns leave free. When only one of `rows`
and `columns` is set and a dimension is left over, it fills the other axis. A position with no image,
such as a map without that sheet, shows a placeholder.

Images keep their full size by default, and a wide grid scrolls sideways. With `fit: true`, a grid
shares the window between its columns in proportion to their full widths, so every image is scaled by
the same amount and text stays the same size across the page. Images are never enlarged. Images that
flow, without rows, columns or `wrap`, always keep their full size.

To place images by hand, give `cells` instead: rows of `map/sheet` references, where map is a map's
`key` or `title`. Use `null` to leave a gap. Images you do not reference are left out.

```yaml
layout:
  cells:
    - [January/Report, February/Report]
    - [January/Raw_Data, null]
```

`examples/lab/compare.yaml` compares January and February examples of the same report with
`columns: map`, and uses YAML anchors so both months share one list of regions:

```bash
uv run sheetmap examples/lab/compare.yaml
```

The command line overrides the file's layout: `--sections`, `--rows`, `--columns`, `--wrap N` and
`--fit`/`--no-fit`. Giving `--rows`, `--columns` or `--wrap` replaces the file's arrangement:

```bash
uv run sheetmap examples/lab/compare.yaml --rows sheet --columns map --fit
```

## Review mappings

Review tools are off by default. Turn them on with `--review`, or `review: true` in the map file;
`--no-review` overrides the file.

```bash
uv run sheetmap examples/lab/map.yaml --review
```

Each label then opens a dialogue for marking the range for removal or proposing a replacement,
with a note. **Review summary** collects the requests as text to copy. Requests are kept in the
browser's storage where it is available, and they change nothing in the workbooks or maps.

## Output

`sheetmap MAP` writes `MAP.html` beside the map, unless you give `-o` or `--output`. Beside it,
`MAP_assets/` holds a PNG per sheet and `manifest.json`, which lists each image with its regions,
their resolved areas and their axis labels.

- Only sheets with regions are drawn.
- Formula cells show the values Excel last saved; nothing is recalculated.
- Charts and images in the workbook are not drawn.
- Workbooks are opened for reading and never saved.
- An existing HTML file is replaced only if sheetmap wrote it. PNGs from earlier runs with other
  names are left in place.

Without `--review` the page has no script. The page and PNGs contain the workbooks' contents, so share
them only with people who may see that data.

## Use from Python

```python
from sheetmap import Layout, Preview, Region, SheetMap, render

render(
    [
        SheetMap(
            "january.xlsx",
            [
                Region("patient", "Report!B3"),
                Region("results", "Report!A7:D", columns={"A": "sample_id", "C": "analyte", "D": "value"}),
            ],
            title="Lab report",
            preview={"Raw_Data": Preview(rows=40, columns=20)},
        )
    ],
    "maps.html",
    layout=Layout(columns="map"),
    review=False,
)
```

`sheetmap.check(maps)` checks maps against their workbooks without writing anything, and
`sheetmap.load_map_file(path)` reads a map file into a `MapFile` holding its maps and page settings. Problems raise `sheetmap.SheetmapError`.

## Development

```bash
make install   # uv sync
make test
make lint
```

`scripts/build_example.py` rebuilds the example workbooks.

Text is drawn with DejaVu Sans or Arial when the system has one, and Pillow's built-in font
otherwise, so images can differ slightly between machines.

## Releasing

Versions come from git tags. To release from a clean `main`:

```bash
make release-check VERSION=0.1.0   # build locally at that version without tagging
make release VERSION=0.1.0         # tag v0.1.0 and push it
```

Pushing the tag runs the publish workflow. It reruns CI, builds the sdist and wheel, uploads them to
PyPI through trusted publishing (the `pypi` environment), and creates a GitHub release with the
built files attached.
