Skip to main content

A fast and configurable CLI tool and library for converting Excel sheets into clean Markdown tables.

Project description

xl2md

A simple, fast, and configurable utility to convert sheets in an Excel workbook into clean Markdown tables.

Manually copying data from Excel into Markdown is tedious and error-prone. xl2md automates this process, preserving the structure of your sheets and providing a command-line tool for quick conversions and a Python library for advanced control.

Key Features

  • Batch Conversion: Automatically converts every sheet in a workbook to a separate Markdown file.
  • Simple CLI: A straightforward command-line interface for easy use in any terminal.
  • Flexible Library: Import the converter into your own Python scripts for customized workflows.
  • Smart Formatting: Handles common Excel quirks like Unnamed: columns and correctly escapes special Markdown characters.
  • Safe Filenames: Automatically creates "slugified," web-safe filenames from sheet names (e.g., "Q3 Financial Report" becomes Q3-Financial-Report.md).
  • Customizable: Control the output directory, overwrite behavior, and more.

Installation

You can install xl2md directly from PyPI using pip.

pip install xl2md

Usage

xl2md can be used as a command-line tool or as a Python library.

1. Command-Line Interface (CLI)

This is the quickest way to convert a file. The basic command requires only the path to your Excel workbook.

Basic Conversion

xl2md path/to/your/workbook.xlsx

By default, this command will:

  1. Read the workbook.xlsx file.
  2. Create a new directory named markdown_sheets in your current location.
  3. Save each converted sheet as a separate .md file inside markdown_sheets.

CLI Options

You can customize the behavior with the following options:

  • --out-dir <directory>: Specifies a different output directory for the Markdown files.

    xl2md my_data.xlsx --out-dir "converted_docs"
    
  • --overwrite: Overwrites existing Markdown files in the output directory if they have the same name. Without this flag, existing files will be skipped.

    xl2md my_data.xlsx --overwrite
    
  • --no-safe-filenames: Uses the original sheet names for filenames instead of converting them to a safe, URL-friendly format. Warning: This may cause issues if sheet names contain special characters.

    xl2md "My Workbook.xlsx" --no-safe-filenames
    
  • -v or --verbose: Enables detailed (DEBUG level) logging, which is helpful for troubleshooting.

    xl2md my_data.xlsx -v
    

Example Combining Options

xl2md "Financial Report Q3 2025.xlsx" --out-dir "reports/markdown" --overwrite --verbose

2. As a Python Library

For more advanced control, import ExcelToMarkdownConverter and ConverterOptions into your own Python scripts. This allows you to filter sheets, include the DataFrame index, and integrate the conversion into a larger automation workflow.

Basic Library Usage

from xl2md import ExcelToMarkdownConverter

# Initialize with the path to your Excel file
converter = ExcelToMarkdownConverter(excel_path="path/to/my_workbook.xlsx")

# Run the conversion with default options
written_files = converter.convert()

print(f"Successfully converted files: {written_files}")

Advanced Configuration

The ConverterOptions class lets you fine-tune the conversion process.

from xl2md import ExcelToMarkdownConverter, ConverterOptions
import logging

# 1. Configure your desired options
options = ConverterOptions(
    out_dir="./custom_output",      # Set a custom output directory
    overwrite=True,                 # Overwrite existing files
    include_index=True,             # Include the DataFrame index in the table
    index_label="Row ID",           # Set a custom label for the index column
    log_level=logging.DEBUG,        # Set the logging level
    
    # Only convert sheets whose names start with "Report_" (uses regex)
    sheet_name_allowlist=[r"Report_.+"],
    
    # Skip any sheets containing the word "Internal" (case-insensitive)
    sheet_name_blocklist=[r"Internal"]
)

# 2. Initialize the converter with the file path and custom options
try:
    converter = ExcelToMarkdownConverter(
        excel_path="financials.xlsx",
        options=options
    )

    # 3. Run the conversion
    written_files = converter.convert()

    if written_files:
        print(f"✅ Conversion complete. Files written to '{options.out_dir}':")
        for f in written_files:
            print(f"  - {f}")
    else:
        print("⚠️ No sheets were converted. Check your allow/block lists and file content.")

except Exception as e:
    print(f"❌ An error occurred: {e}")

Contributing

Contributions are welcome! If you have a suggestion or find a bug, please open an issue on the GitHub repository. Pull requests are also greatly appreciated.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

xl2md-1.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

xl2md-1.2-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file xl2md-1.2.tar.gz.

File metadata

  • Download URL: xl2md-1.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for xl2md-1.2.tar.gz
Algorithm Hash digest
SHA256 9e5164a12210c537e53f2efc1fe65f8987d9be35c26279ba88f3a2cf3aaf13e7
MD5 47bd2100143d6db2836953802d1a40a4
BLAKE2b-256 1a4cd822cedc1bc2b981ff63eb1a3814c6f4d7a7ac288a952b4980797916f1e0

See more details on using hashes here.

File details

Details for the file xl2md-1.2-py3-none-any.whl.

File metadata

  • Download URL: xl2md-1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for xl2md-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 585101c17044ef72fa78d3e625faa852b12310ab93fc9a6e4a6309d5a8779908
MD5 4801371f9413beafdc86669b2363319f
BLAKE2b-256 d0406028e153ce7bc51ed60136b3b63b0721e5d335813152eb01bb1cbd6738d5

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