Skip to main content

Reduce Excel file size by removing empty rows, columns, and excess formatting

Project description

xlsxslim

PyPI version License

Reduce Excel file size by removing empty rows, columns, and excess formatting.

🇺🇦 Документація українською

v2.0.2 uses direct XML/regex manipulation — works with files of any size without memory issues.

Features

  • 🚀 Memory efficient — processes 100+ MB files with < 100 MB RAM
  • 📊 Direct XML — no openpyxl dependency for processing
  • 📁 Auto-detect — finds single xlsx in current directory
  • 💾 Safe — creates _slim copy by default

Installation

pip install xlsxslim

Quick Start

# Auto-detect single xlsx in current directory
xlsxslim

# Optimize specific file
xlsxslim report.xlsx

# Analyze only (dry run)
xlsxslim report.xlsx --dry-run

# Overwrite original file
xlsxslim report.xlsx --inplace

Example Output

xlsxslim v2.0.0

Input:  report.xlsx (68.64 MB)
Memory:  45.00 MB used, 16.00 GB available

Analyzing...

Sheets: 2

Sheet "Data":
  Used range:  A1:J1047716 → A1:I82
  Rows:        1,047,716 → 82 (-1,047,634)
  Columns:     10 → 9 (-1)

Sheet "Summary":
  Used range:  A1:K1047713 → A1:K76
  Rows:        1,047,713 → 76 (-1,047,637)

Optimizing...

Output: report_slim.xlsx (156.00 KB)
Saved:  68.49 MB (99.8%)
Memory:  48.00 MB used, 16.00 GB available

Options

Option Short Description
--output FILE -o Custom output path
--inplace -i Overwrite original file
--dry-run -n Analyze only, don't save
--verbose -v Detailed output
--quiet -q Minimal output
--suffix TEXT -s Output suffix (default: _slim)
--version Show version
--help -h Show help

How It Works

xlsx files are ZIP archives containing XML. xlsxslim:

  1. Analyzes — Scans XML to find actual data bounds
  2. Removes — Strips rows/columns/cells beyond data range
  3. Rebuilds — Creates new ZIP with optimized XML

No need to load entire workbook into memory.

Why Files Get Bloated

Excel tracks a "used range" that includes any cell ever formatted:

  • Ctrl+Shift+End → format applied to row 1,048,576
  • Copy-paste brings invisible formatting
  • Conditional formatting on entire columns
  • Deleted data leaves formatted empty cells

v2.0 vs v1.x

Feature v1.x (openpyxl) v2.0 (XML)
68 MB file 46+ GB RAM, crashes < 100 MB RAM
Speed Slow Fast
Dependencies openpyxl None (stdlib)

Exit Codes

Code Description
0 Success
1 File not found
2 Multiple files (specify explicitly)
3 Read/write error
4 Already optimized

Testing

# Install dev dependencies (includes openpyxl for creating test fixtures)
pip install -r requirements-dev.txt

# Run tests
pytest

# Run with verbose output
pytest -v

License

BSD 3-Clause License

Copyright

Copyright (c) 2025, Vladyslav V. Prodan

Contact

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

xlsxslim-2.0.2.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

xlsxslim-2.0.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file xlsxslim-2.0.2.tar.gz.

File metadata

  • Download URL: xlsxslim-2.0.2.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for xlsxslim-2.0.2.tar.gz
Algorithm Hash digest
SHA256 29d45e60322c2a629d9a2bc1f49822b7e343c176bf87efac66d1b32b927bb67b
MD5 612d7888aea96689c42b142feabe3409
BLAKE2b-256 1761bb6ed4303df994e1635491a07c480e12acb08352ad7c7df859d8ae4c1986

See more details on using hashes here.

File details

Details for the file xlsxslim-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: xlsxslim-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for xlsxslim-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d4765fe070ef41aee9d17144bab04ee5a7b9d1da98e7a82e217c5ec048bdde1b
MD5 9bc3239ffb3167fc0c7ef22c162ee9ca
BLAKE2b-256 7469d431df31bcc5201f2a882280fc595ea2fc13c32fa9e14488c0c4f8f15e6c

See more details on using hashes here.

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