在空间网格系统中组织数据以进行cals、html、formex4、office open xml表转换
Benker的Python项目详细描述
在空间网格系统中组织数据以进行CAL、HTML、FormEx4、Office Open XML表转换
概述
若要将.docx文档的表转换为CALS格式,可以按如下方式处理:
importosimportzipfilefrombenker.converters.ooxml2calsimportconvert_ooxml2cals# - Unzip the ``.docx`` in a temporary directorysrc_zip="/path/to/demo.docx"tmp_dir="/path/to/tmp/dir/"withzipfile.ZipFile(src_zip)aszf:zf.extractall(tmp_dir)# - Source pathssrc_xml=os.path.join(tmp_dir,"word/document.xml")styles_xml=os.path.join(tmp_dir,"word/styles.xml")# - Destination pathdst_xml="/path/to/demo.xml"# - Create some options and convert tablesoptions={'encoding':'utf-8','styles_path':styles_xml,'width_unit':"mm",'table_in_tgroup':True,}convert_ooxml2cals(src_xml,dst_xml,**options)
安装
要安装此库,可以创建并激活virtualenv,然后运行:
pip install benker
要求
此库使用lxml库,并使用3.x版(对于python<;3.7)和4.x版进行测试。
在库/应用程序中的使用
您可以在自己的库/应用程序中使用此库。
为此,请在项目需求中的setup.py中添加此库:
setup(name="YourApp",install_requires=['benker'],...)
要安装依赖项,请激活virtualenv并运行:
pip install -e .
好好享受吧!