使用 Python 将 Word 文档转换为 HTML 或 Markdown
马哥Linux运维
共 1283字,需浏览 3分钟
·
2021-09-12 21:48
这篇简短的文章将指导您如何在基于 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
with open("sample.docx", "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
with open("sample.html", "w") as html_file:
html_file.write(result.value)
将Docx 转换为MD
使用命令行:
mammoth .\sample.docx output.md --output-format=markdown
使用Python:
with open("sample.docx", "rb") as docx_file:
result = mammoth.convert_to_markdown(docx_file)
with open("sample.md", "w") as markdown_file:
markdown_file.write(result.value)
文章转载:Python编程学习圈
(版权归原作者所有,侵删)
点击下方“阅读原文”查看更多
评论
HTML To Markdown for PHP将 HTML 转换为 Markdown 的库
HTML To Markdown 是一款使用 PHP 将 HTML 转换为 Markdown 的库。
HTML To Markdown for PHP将 HTML 转换为 Markdown 的库
0
HTML To Markdown for PHP将 HTML 转换为 Markdown 的库
HTMLToMarkdown是一款使用PHP将HTML转换为Markdown的库。要求:PHP7.2+为什么要将HTML转换为Markdown?通常在以下情况下,你会将HTML转换为Markdown:
HTML To Markdown for PHP将 HTML 转换为 Markdown 的库
0
Lute DOCX将 Markdown 转换为 Word 的工具
LuteDOCX是一款将Markdown文本转换为Word文档(.docx)的小工具。通过 Lute 解析Markdown然后再通过 unioffice 生成DOCX。特性几乎支持所有Markdown
Lute DOCX将 Markdown 转换为 Word 的工具
0
Lute DOCX将 Markdown 转换为 Word 的工具
Lute DOCX 是一款将 Markdown 文本转换为 Word 文档 (.docx) 的小工具
Lute DOCX将 Markdown 转换为 Word 的工具
0
xoffice将 Office 文档转换为 PDF
一个JavaEE服务,将Office文档转换为PDF,格式兼容性好。 安装部署安装微软Office
xoffice将 Office 文档转换为 PDF
0