使用mammoth将.docx文件转换为与.docx同名的html文件

2024-06-26 04:43:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个代码将(.doc)转换为HTML文件。代码是:

import mammoth
f=open("c: ......\\demo.docx","rb")
b=open("ABC.html","wb") 
document=mammoth.convert_to_html(f) 
b.write(document.value.encode('utf8')) 

现在ABC.html将被创建。相反,我需要用与docx文件相同的名称转换HTML文档


Tags: 文件代码importconvertdocdemohtmlopen
1条回答
网友
1楼 · 发布于 2024-06-26 04:43:34

您可以决定将哪个文件名用于输出文件-您可以使用相同的名称:

dir = 'c:\...'
filename = 'demo'
input_file = os.path.join(dir, filename + '.docx')
output_file = filename + '.html'
f = open(input_file, "rb")
b = open(output_file,"wb") 

相关问题 更多 >