安裝
sudo apt install pandoc
pip3 install pypandoc
示例代碼
import pypandochtml = """
<h3>This is a title</h3>
<p><img src="http://placehold.it/150x150" alt="I go below the image as a caption"></p>
<p><i>This is <b>some</b> text</i> in a <a href="http://google.com">paragraph</a></p>
<ul><li>Boo! I am a <b>list</b></li>
</ul>
"""
output = pypandoc.convert_file('1.html', 'docx', outputfile="file1.docx") # 將網頁直接轉換成docx
output = pypandoc.convert_text(html, 'docx', 'html', outputfile="file1.docx") # 將 html 代碼轉化成docx
其他
這種轉換不能使生成的word與html完全一致,其中包括字體顏色,背景色等都不能顯示,但是大致相同