如何在python中使用win32com将带有图像的html转换为word
我正在使用win32com将html转换为python中的word(Django) 我面临图像部分的问题,即html页面包含最终word文档中没有的图像如何在python中使用win32com将带有图像的html转换为word,python,html,ms-word,Python,Html,Ms Word,我正在使用win32com将html转换为python中的word(Django) 我面临图像部分的问题,即html页面包含最终word文档中没有的图像 import win32com.client word = win32com.client.Dispatch('Word.Application') doc = word.Documents.Add('example.html') doc.SaveAs('example.doc', FileFormat=0) doc.Close() wo
import win32com.client
word = win32com.client.Dispatch('Word.Application')
doc = word.Documents.Add('example.html')
doc.SaveAs('example.doc', FileFormat=0)
doc.Close()
word.Quit()
这是我使用的代码。对此可以做些什么?不幸的是,这似乎是Word的一个缺点。有关更多信息,请参阅 “最简单”的解决方案是打开html文档,选择全部,复制,然后粘贴到新文档中。这将嵌入图像
import os
import win32com.client
word = win32com.client.Dispatch("Word.Application")
in_file = os.path.abspath("example.html")
in_name = os.path.splitext(os.path.split(in_file)[1])[0]
out_file = os.path.abspath("%s.doc" % in_name)
# Open and copy HTML
doc = word.Documents.Add(in_file)
word.Selection.WholeStory()
word.Selection.Copy()
doc.Close()
# Open new document, paste HTML and save
doc = word.Documents.Add()
word.Selection.Paste()
doc.SaveAs(out_file, FileFormat=0)
doc.Close()
word.Quit()