使用 Python 将 Word 文档转换为 HTML 或 Markdown
这篇简短的文章将指导您如何在基于Python 的 CLI —Mammoth的帮助下,以简单的方式将 .docx word 文档转换为简单的网页文档 ( .html ) 或 Markdown 文档 ( .md ) 。
据统计Statista调查(2020年1月6日),Microsoft Office套件是目前最流行的办公软件。您可以使用 Microsoft Word 轻松地做快速笔记、简短报告、教程文档等。而且,您可能希望将文档内容作为 Web 文档 ( .html )) 或 Markdown 文档 ( .md )与您的一些朋友、同事、客户共享。过去,在网络上托管一些网络文档可能会很昂贵,但现在云服务对于公共文档(例如GitHub Pages)来说非常便宜甚至免费。
Install Mammoth
确保PC 上安装了 Python 和 PIP。然后,打开 CMD 或终端并使用以下命令:
pip install mammoth
将Docx 转换为HTML
使用命令行:
mammoth input_name.docx output_name.html
使用Python:
import mammoth
withopen("sample.docx", "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
withopen("sample.html", "w") as html_file:
html_file.write(result.value)
将Docx 转换为MD
使用命令行:
mammoth .\sample.docx output.md --output-format=markdown
使用Python:
withopen("sample.docx", "rb") as docx_file:
result = mammoth.convert_to_markdown(docx_file)
withopen("sample.md", "w") as markdown_file:
markdown_file.write(result.value)
文章转载:Python编程学习圈
(版权归原作者所有,侵删)
(版权归原作者所有,侵删)
点击下方“阅读原文”查看更多
关键词
文档
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。