Python:将Word转成HTML

图片在转换结果中,会以Base64编码的方式编码。

前置条件:安装pydocx

pip install pydocx

from pydocx import PyDocX
html = PyDocX.to_html("test.docx")
f = open("test.html", 'w', encoding="utf-8")
f.write(html)
f.close()

通过网页上传word文档,只接收docx

<form method="post" enctype="multipart/form-data">
<input type="file" name="file" accept="application/vnd.openxmlformats-officedocument.wordprocessingml.document">
</form>

windows下,将doc转为docx

pip3 install pypiwin32

from win32com import client
word = client.Dispatch("Word.Application")
doc = word.Documents.Open("D:\\***\\**.doc") //绝对路径 doc文件
doc.SaveAs("D:\\***\\**.docx",16) //保存的docx 文件,绝对路径
doc.Close()
word.Quit()

猜你喜欢

转载自blog.csdn.net/qcyfred/article/details/86688688
今日推荐