Convert Excel files (xlsx, xls) and CSV to Markdown tables
Project description
xlsx2md
xlsx2md is a powerful CLI tool for converting Excel files (.xlsx, .xls) and CSV to Markdown tables with support for multiple sheets, cell ranges, and various table styles.
✨ Features
- 🔄 Format support: Excel (.xlsx, .xls) and CSV files
- 📊 Multiple sheets: process all or selected sheets
- 🎨 Table styles: default, minimal, grid
- 📏 Alignment: left, center, right for columns
- 🔍 Cell ranges: process specific areas
- 📋 File info: view structure and metadata
- 🎯 Flexible options: empty cells, encodings, delimiters
🚀 Installation
Using pip
pip install xlsx2md
Using pipx (recommended)
pipx install xlsx2md
From source
git clone https://github.com/postovalov/xlsx2md.git
cd xlsx2md
pip install -e .
🎯 Quick Start
Basic usage
# Convert Excel file to Markdown
xlsx2md data.xlsx
# Convert with specific sheet
xlsx2md data.xlsx --sheet "Sheet2"
# Convert cell range
xlsx2md data.xlsx --range "A1:C10"
# Save to file
xlsx2md data.xlsx --output table.md
Table style examples
# Default style
xlsx2md data.xlsx
# Minimal style
xlsx2md data.xlsx --style minimal
# Grid style
xlsx2md data.xlsx --style grid
📁 Supported Formats
| Format | Extension | Description |
|---|---|---|
| Excel 2007+ | .xlsx |
Modern Excel format |
| Excel 97-2003 | .xls |
Legacy Excel format |
| CSV | .csv |
Text format with delimiter |
📖 Usage
Basic syntax
xlsx2md [OPTIONS] FILE_PATH
Parameters
Main parameter
FILE_PATH- path to input file (required)
Sheet options
--sheet, -s TEXT- sheet name or index (default: first sheet)--all-sheets- process all sheets--sheets TEXT- process specific sheets (1,3,5 or "Sheet1,Sheet3")--list-sheets- show all sheets
Range options
--range, -r TEXT- cell range (e.g., A1:B10)
Output options
--output, -o PATH- output file path (default: stdout)--style TEXT- table style: default, minimal, grid (default: default)--align TEXT- column alignment: left, center, right--empty TEXT- value for empty cells (default: empty string)
Info options
--info- show file information--version, -V- show version and exit--help, -h- show help
📊 Examples
1. Basic conversion
xlsx2md sales_data.xlsx
Result:
| Product | Q1 | Q2 | Q3 | Q4 |
|----------|-----|-----|-----|-----|
| Widget A | 100 | 120 | 110 | 130 |
| Widget B | 80 | 90 | 85 | 95 |
| Widget C | 150 | 160 | 155 | 165 |
2. Table styles
Default style
xlsx2md data.xlsx --style default
Minimal style
xlsx2md data.xlsx --style minimal
Result:
Product | Q1 | Q2 | Q3 | Q4
---------|-----|-----|-----|-----
Widget A | 100 | 120 | 110 | 130
Widget B | 80 | 90 | 85 | 95
Grid style
xlsx2md data.xlsx --style grid
Result:
+----------+-----+-----+-----+-----+
| Product | Q1 | Q2 | Q3 | Q4 |
+----------+-----+-----+-----+-----+
| Widget A | 100 | 120 | 110 | 130 |
| Widget B | 80 | 90 | 85 | 95 |
+----------+-----+-----+-----+-----+
3. Column alignment
xlsx2md data.xlsx --align center
4. Handling empty cells
xlsx2md data.xlsx --empty "-"
5. Working with ranges
xlsx2md data.xlsx --range "B2:D5"
6. All sheets
xlsx2md data.xlsx --all-sheets --output all_tables.md
7. Specific sheets
xlsx2md data.xlsx --sheets "1,3,5"
xlsx2md data.xlsx --sheets "Sheet1,Sheet3"
8. File info
xlsx2md data.xlsx --list-sheets
xlsx2md data.xlsx --info
⚙️ Configuration
Environment variables
| Variable | Description | Default |
|---|---|---|
XLSX2MD_ENCODING |
Encoding for CSV files | utf-8 |
XLSX2MD_MAX_FILE_SIZE |
Max file size (MB) | 100 |
XLSX2MD_MAX_ROWS |
Max number of rows | 10000 |
XLSX2MD_OUTPUT_FORMAT |
Output format | markdown |
XLSX2MD_COLORS |
Enable colored output | true |
XLSX2MD_VERBOSE |
Verbose output | false |
XLSX2MD_LOG_LEVEL |
Logging level | WARNING |
Example usage
export XLSX2MD_ENCODING=cp1251
export XLSX2MD_MAX_FILE_SIZE=200
xlsx2md large_file.xlsx
🛠️ Development
Install for development
git clone https://github.com/postovalov/xlsx2md.git
cd xlsx2md
pip install -e ".[dev]"
Run tests
# All tests
pytest
# With coverage
pytest --cov=xlsx2md
# Specific tests
pytest tests/test_cli.py
Code quality
# Formatting
black xlsx2md tests
# Linting
flake8 xlsx2md tests
# Type checking
mypy xlsx2md
Pre-commit hooks
pre-commit install
pre-commit run --all-files
📋 Requirements
- Python 3.8+
- openpyxl >= 3.0.0
- xlrd >= 2.0.0
- typer >= 0.9.0
- rich >= 13.0.0
🤝 Contributing
- Fork the repository
- Create a new branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🐛 Issues
If you find a bug or have a suggestion, please create an issue on GitHub.
📈 Roadmap
- Google Sheets support
- Export to HTML tables
- Excel formulas support
- Interactive mode
- Plugin system for extensions
Author: Roman Postovalov Email: rpostovalov@gmail.com GitHub: postovalov
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xlsx2md-0.1.1.tar.gz.
File metadata
- Download URL: xlsx2md-0.1.1.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90f5ef067996efdf1a661c0b3413424f9cf9b61158b6895c0d8a3efdf5a32159
|
|
| MD5 |
98f3e7cf6afc4175b35841130120fa9f
|
|
| BLAKE2b-256 |
1cd8b73dd146a5900634dd8c81bfea5a3ed96f2b6baf8f8525629340a3b8cb81
|
File details
Details for the file xlsx2md-0.1.1-py3-none-any.whl.
File metadata
- Download URL: xlsx2md-0.1.1-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32ad193c5cbf655887e3cca563e30ac5c044fbaa2e63f84a12c21ae7a62033d9
|
|
| MD5 |
86c0ad6c2d1811b1ed3748850a20ef37
|
|
| BLAKE2b-256 |
676b86bb9b7149d20f30b8ec79f899a671c814b86c4110d4f4bea556896df6be
|