https://github.com/ivbeg/docx2csv
Extracts tables from .docx files and saves them as .csv or .xls files
https://github.com/ivbeg/docx2csv
csv docx extract-tables parsing python
Last synced: 1 day ago
JSON representation
Extracts tables from .docx files and saves them as .csv or .xls files
- Host: GitHub
- URL: https://github.com/ivbeg/docx2csv
- Owner: ivbeg
- License: bsd-3-clause
- Created: 2016-08-10T15:15:17.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-10-11T12:07:05.000Z (over 2 years ago)
- Last Synced: 2025-11-03T01:19:32.249Z (5 months ago)
- Topics: csv, docx, extract-tables, parsing, python
- Language: Python
- Size: 245 KB
- Stars: 65
- Watchers: 5
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- Contributing: CONTRIBUTING.rst
- License: LICENSE
Awesome Lists containing this project
README
============
Command line
============
Usage: docx2csv extract [OPTIONS] FILENAME
docx to csv convertor (http://github.com/ivbeg/docx2csv)
Extracts tables from DOCX files as CSV or XLSX.
Use command: "docx2csv convert " to run extraction. It will
create files like filename_1.csv, filename_2.csv for each table found.
Options:
--format TEXT Output format: CSV, XLSX
--singlefile TEXT Outputs single XLS file with multiple sheets: True or False
--sizefilter INTEGER Filters table by size number of rows
--help Show this message and exit.
Examples
========
docx2csv extract --format csv --sizefilter 3 CP_CONTRACT_160166.docx
Extracts tables from file CP_CONTRACT_160166.docx with number of rows > 3 and
saves results as CSV files.
Code
====
Function "extract_tables" returns list of tables from docx file and function "extract" extracts tables as xlsx, xls or csv file. If 'csv' file selected you need to specify single file csv or multiple files
>>> from docx2csv import extract_tables, extract
>>> tables = extract_tables('some_file.docx')
returns list of tables
>>> extract(filename='some_file.docx', format="xlsx", output='some_file.xlsx')
saves all tables from some_file.docx to some_file.xlsx
>>> extract(filename='some_file.docx', format="csv", singlefile=False)
saves all tables from some_file.docx to some_file_1.csv, some_file_2.csv and etc.
Requirements
============
* click https://github.com/pallets/click
* xlwt https://github.com/python-excel/xlwt
* python-docx https://github.com/python-openxml/python-docx
* openpyxl https://bitbucket.org/openpyxl/openpyxl/src
Acknowledgements
================
Thanks to Vsevolod Oparin (https://www.facebook.com/vsevolod.oparin) for optimized "extract_table" code