Easily convert your CALS, HTML, Formex4, Office Open XML (docx) tables from one format to another.
To convert the tables of a .docx
document to CALS format, you can process as follow:
import os
import zipfile
from benker.converters.ooxml2cals import convert_ooxml2cals
# - Unzip the ``.docx`` in a temporary directory
src_zip = "/path/to/demo.docx"
tmp_dir = "/path/to/tmp/dir/"
with zipfile.ZipFile(src_zip) as zf:
zf.extractall(tmp_dir)
# - Source paths
src_xml = os.path.join(tmp_dir, "word/document.xml")
styles_xml = os.path.join(tmp_dir, "word/styles.xml")
# - Destination path
dst_xml = "/path/to/demo.xml"
# - Create some options and convert tables
options = {
'encoding': 'utf-8',
'styles_path': styles_xml,
'width_unit': "mm",
'table_in_tgroup': True,
}
convert_ooxml2cals(src_xml, dst_xml, **options)
To install this library, you can create and activate a virtualenv, and run:
pip install benker
This library uses lxml library and is tested with the versions 3.8 and 4.*x*.
The following table shows the compatibility between different combinations of Python and lxml versions:
Py ╲ lxml | 3.8 | 4.0 | 4.1 | 4.2 | 4.3 | 4.4 | 4.5 | 4.6 |
---|---|---|---|---|---|---|---|---|
2.7 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
3.4 | ✔️! | ✔️! | ✔️! | ✔️! | ✔️! | ✖️ | ✖️ | ✖️ |
3.5 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
3.6 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
3.7 | ✖️ | ✖️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
3.8 | ✖️ | ✖️ | ✖️ | ✖️ | ✔️ | ✔️ | ✔️ | ✔️ |
3.9 | ✖️ | ✖️ | ✖️ | ✖️ | ✔️ | ✔️ | ✔️ | ✔️ |
- ✔️ lxml is available for this version and unit tests succeed.
- ! installation succeed using "attrs < 21.1".
- ✖️ lxml is not available for this version of Python.
You can use this library in your own library/application.
To do so, add this library in your setup.py
in your project requirements:
setup(
name="YourApp",
install_requires=['benker'],
...
)
To install the dependencies, activate your virtualenv and run:
pip install -e .
And enjoy!
This library is distributed according to the MIT licence.
Users have legal right to download, modify, or distribute the library.
Benker
was written by Laurent LAPORTE.