Skip to main content

Fill empty Excel cells inside a selected range, with optional vertical merge support.

Project description

excel-fill-na

excel-fill-na is a small pip-installable library with an fna CLI for filling empty Excel cells inside a selected range.

It supports:

  • filling empty cells with NA or custom text
  • skipping one or more excluded ranges
  • optionally merging contiguous empty cells vertically within a column before filling them
  • preserving comment-only cells without filling or merging them
  • working against the active worksheet or a named sheet

The implementation uses openpyxl to inspect workbook contents and compute fill operations, then patches only the target worksheet XML inside the workbook archive when saving. That keeps existing drawings, charts, images, and other unsupported workbook parts intact instead of round-tripping the whole file through openpyxl.save(). .xlsx and .xlsm are supported. .xls is not supported.

Pillow is not required to preserve existing workbook images. It is only relevant if you want to create new images through openpyxl itself. The committed test fixture under tests/fixtures/ does not require Pillow at test runtime.

Install

From PyPI:

pip install excel-fill-na

From a local checkout:

pip install .

For development:

python3 -m venv .venv
.venv/bin/python -m pip install -e ".[dev]"

CLI Usage

fna workbook.xlsx \
  --sheet Sheet1 \
  --range A1:C20 \
  --exclude-range B2:B4 \
  --exclude-range C10 \
  --fill-text MISSING \
  --merge-empty-runs \
  --output workbook.filled.xlsx

CLI options

  • input_path: source workbook path
  • --sheet: worksheet name, defaults to the active sheet
  • --range: target range to inspect, required
  • --exclude-range: ranges to leave untouched; repeat the flag or pass comma-separated ranges
  • --fill-text: replacement text, defaults to NA
  • --merge-empty-runs: merge contiguous empty cells vertically within each column before filling
  • --output: destination path, defaults to <input>.filled<suffix>

Python Usage

from excel_fill_na import process_workbook

result = process_workbook(
    "workbook.xlsx",
    target_range="A1:C20",
    excluded_ranges=["B2:B4", "C10"],
    fill_value="NA",
    merge_empty_runs=True,
)

print(result.output_path)
print(result.filled_cells)
print(result.merged_ranges)

Merge behavior

When merge_empty_runs=True, the library scans each column in the selected range and looks for contiguous empty cells. Runs of length 2 or more are merged vertically and the top cell is filled with the requested value.

Example:

  • A1, A2, and A3 are empty
  • A4 contains data
  • target range is A1:A4
  • merge mode creates A1:A3 and fills A1 with NA

Existing merged cells are supported. If an existing merged range has an eligible empty anchor cell, the anchor is filled, but the library does not attempt to re-merge or resize that existing merged range.

Comment behavior

Only truly empty cells are modified. If a cell has no value but does have a comment, the library preserves that cell as-is:

  • it is not filled with NA or custom text
  • it is not included in a generated merge run
  • it breaks a vertical empty run when merge_empty_runs=True

Cells that already contain a value are untouched regardless of whether they also have a comment.

Specs

Tests

.venv/bin/pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

excel_fill_na-0.1.1.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

excel_fill_na-0.1.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file excel_fill_na-0.1.1.tar.gz.

File metadata

  • Download URL: excel_fill_na-0.1.1.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for excel_fill_na-0.1.1.tar.gz
Algorithm Hash digest
SHA256 adaeb00d8c9eac756f771df388330cd3453e4efbe118d8eff5b315ecd77756de
MD5 ad0566e205cc6e690bb0331d6ef9d321
BLAKE2b-256 04ba6bc113189e8fc7efb15cc6e962054e02921fafa2e62ce54719919969491c

See more details on using hashes here.

Provenance

The following attestation bundles were made for excel_fill_na-0.1.1.tar.gz:

Publisher: publish.yml on dews/excel-fill-na

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file excel_fill_na-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: excel_fill_na-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for excel_fill_na-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0483d3a1136f81ee76254bb5f88b979422b8d32553e984496ece0870190eae76
MD5 21b86173b1b33b562c611ab4c8bef66d
BLAKE2b-256 9755e30e2474e8ea49d78bb2ff2e3e06ab40ed81c4cdb779b4f10a30e338f104

See more details on using hashes here.

Provenance

The following attestation bundles were made for excel_fill_na-0.1.1-py3-none-any.whl:

Publisher: publish.yml on dews/excel-fill-na

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page