将HTML转换为docx
htmldocx的Python项目详细描述
htmldocx
将HTML转换为docx
依赖项:python-docx
&;bs4
(如果要在转换或提取表之前修复html)
安装
pip install htmldocx
使用量
将HTML字符串添加到现有的DOX.Object对象
from docx import Document from htmldocx import HtmlToDocx document = Document() new_parser = HtmlToDocx() # do stuff to document html = '<h1>Hello world</h1>' new_parser.add_html_to_document(html, document) # do more stuff to document document.save('your_file_name')
直接转换文件
new_parser.parse_html_file(input-html-file, output-docx-file)
指定选项:选项默认为True
。运行前设置为False
以禁用提取功能
new_parser.options['tables'] = False
当前可用选项:tables
,images