如何使用python将.docx文件转换为html? [英] how to convert .docx file to html using python?

查看:79
本文介绍了如何使用python将.docx文件转换为html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import mammoth

f = open("D:\filename.docx", 'rb')
document = mammoth.convert_to_html(f)

我在运行此代码时无法获取 .html 文件,请帮助我获取它,当我转换为 .html 文件时,我没有将图像插入到 .html 文件中,请您帮忙我如何将图像从 .docx 转换为 .html?

I am unable to get a .html file while i run this code,please help me to get it, When i converted to .html file i am not getting images inserted into word file into .html file,Can you please help me how to get images into .html from .docx?

推荐答案

试试这个:

import mammoth

f = open("path_to_file.docx", 'rb')
b = open('filename.html', 'wb')
document = mammoth.convert_to_html(f)
b.write(document.value.encode('utf8'))
f.close()
b.close()

这篇关于如何使用python将.docx文件转换为html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆