Extracts tables from .docx files and saves them as csv or xlsx
Project description
docx2csv
Extracts tables from .docx files and saves them as CSV, TSV, XLSX, or JSON.
Installation
pip install docx2csv
For XLS (Excel 97) output support:
pip install docx2csv[xls]
Quick Start
Command Line
# Extract all tables as separate CSV files
docx2csv extract document.docx
# Extract as XLSX
docx2csv extract document.docx --format xlsx
# Extract as single CSV file with all tables
docx2csv extract document.docx --format csv --singlefile
# Filter tables by minimum row count
docx2csv extract document.docx --sizefilter 3
# Specify output location
docx2csv extract document.docx --output results.csv
# Analyze a document (list tables without extracting)
docx2csv analyze document.docx
Python API
from docx2csv import extract_tables, extract, analyze
# Get table data as Python objects
tables = extract_tables('document.docx')
for table in tables:
print(f"Table {table['id']}: {table['num_rows']} rows x {table['num_cols']} cols")
for row in table['data']:
print(row)
# Extract to file
extract('document.docx', format='xlsx', output='output.xlsx')
# Analyze document structure
info = analyze('document.docx')
Output Formats
| Format | Extension | Description |
|---|---|---|
| CSV | .csv |
Comma-separated values |
| TSV | .tsv |
Tab-separated values |
| XLSX | .xlsx |
Excel 2007+ (via openpyxl) |
| XLS | .xls |
Excel 97 (requires pip install docx2csv[xls]) |
| JSON | .json |
Structured JSON with metadata |
Requirements
Contributing
Contributions are welcome! Every little bit helps.
- Fork the repo on GitHub
- Clone your fork:
git clone https://github.com/your-username/docx2csv.git - Create a branch:
git checkout -b name-of-your-bugfix-or-feature - Make your changes and add tests
- Run tests:
pytest - Commit and push:
git commit -m "Your message" && git push origin your-branch - Submit a pull request
Credits
- Ivan Begtin - Author and maintainer
- Vsevolod Oparin - Optimized table extraction code
License
BSD 3-Clause License. See LICENSE for details.
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
docx2csv-0.1.4.tar.gz
(9.4 kB
view details)
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 docx2csv-0.1.4.tar.gz.
File metadata
- Download URL: docx2csv-0.1.4.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
501fd0dd2041dc5dec1f1e27222d7230a41d253b9b1617d2bf5cf4c99f2583e6
|
|
| MD5 |
84a5314813b90626b8982820fad7fd79
|
|
| BLAKE2b-256 |
6617d39191ba2795bd444c08ed9fb6fb1194e3867081b06f9672ef660da8b1f9
|
File details
Details for the file docx2csv-0.1.4-py2.py3-none-any.whl.
File metadata
- Download URL: docx2csv-0.1.4-py2.py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
241342b445e3d93202efe34b66fc54cc8a0242dd060e001fe2520a881f13acb6
|
|
| MD5 |
3e608f6a08f90dd4f473ddf6263a88b2
|
|
| BLAKE2b-256 |
44183504efd3d20899639760c806d6e2914d0a93e48c8141140a4b4379bf0a8f
|